我正在写一个自定义指令。
<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中放入什么参数。
非常感谢。
发布于 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?
https://stackoverflow.com/questions/29292211
复制相似问题