首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AngularJS通过自定义指令传递单击的项目

AngularJS通过自定义指令传递单击的项目
EN

Stack Overflow用户
提问于 2015-03-27 10:18:38
回答 1查看 82关注 0票数 0

我正在写一个自定义指令。

代码语言:javascript
复制
<ng-selectbox select-function="selectitem(codes)" items="codes"></ng-selectbox> 

code.controller("codeCtrl", function($scope) {  
  $scope.selectitem = function(item){
    alert(item);
  };
});

code.directive("ngSelectbox", function(){
  return {
    restrict: "E",
    scope: {
      items: "=",
      selectFunction: "&"
    },
    template:
    "<div>" +
    "<ul ng-repeat='item in items'>" +
    "<li ng-click='selectFunction(item)'>{{item.TYPE}}</li>" +
    "</ul>" +
    "</div>"
  };
});

当单击ng-repeat中的项时,我希望通过selectFunction传递单击的项,但它不起作用。:(

我不知道应该在html select-function中放入什么参数。

非常感谢。

EN

回答 1

Stack Overflow用户

发布于 2015-03-27 11:40:16

您是否可以尝试将模板更改为

"<li ng-click='selectFunction({item:item})'>{{item.TYPE}}</li>"

并检查它是否正常工作。

查看我最老的答案,了解更多上下文Can an angular directive pass arguments to functions in expressions specified in the directive's attributes?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29292211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档