Angularjs 在指令的模板中,我添加了在链接中处理的click事件,但问题是函数调用了两次
这是我的指令。在此指令中,我添加了带有项目名称显示的li的ng click,但函数调用了两次。请任何人解释一下它的发生。下面的代码JSFIDLE链接可用于我的问题Angularjs 在指令的模板中,我添加了在链接中处理的click事件,但问题是函数调用了两次,angularjs,angularjs-directive,angularjs-scope,angular-ui,Angularjs,Angularjs Directive,Angularjs Scope,Angular Ui,这是我的指令。在此指令中,我添加了带有项目名称显示的li的ng click,但函数调用了两次。请任何人解释一下它的发生。下面的代码JSFIDLE链接可用于我的问题 angular.module("myApp", []) .directive("myDirective", function () { return { restrict: 'EA', replace: true, scope: {
angular.module("myApp", [])
.directive("myDirective", function () {
return {
restrict: 'EA',
replace: true,
scope: {
combo: '=combo'
},
template: '<ul ng-repeat="comboCollection in combo.comboCollections">'+'<li ng-click="testing(comboCollection.comboItemName)">'+
'<label>'+
'<input type="radio" name="{{comboCollection.comboItemName}}" value="{{comboCollection.comboItemName}}" ng-show="comboCollection.havingSub" id={{comboCollection.comboItemCode}} ng-checked="true">'+
'{{comboCollection.comboItemName}}'+'</label>'+
'</li>' +'<li ng-repeat="substitute in combo.itemSubstitutes" ng-show="substitute.forItem==comboCollection.comboItemCode" ng-click="testing(substitute.subItemName)">'+
'<label>'+
'<input type="radio" id="{{comboCollection.comboItemCode}}-{{substitute.subItemCode}}" name="{{comboCollection.comboItemName}}" value="{{substitute.subItemName}}">'+'{{substitute.subItemName}}'+'</label>'+'</li>'+'</ul>',
link:function(scope) {
scope.testing=function(code){
console.log("details");
alert(code);
};
}
}
});
angular.module(“myApp”,[])
.指令(“myDirective”,函数(){
返回{
限制:“EA”,
替换:正确,
范围:{
组合:'=组合'
},
模板:“”+“- ”+
''+
''+
“{comboCollection.comboItemName}}”+”+
“
”+”- ”+
''+
'+'{{substitute.subItemName}}'+'+'
'+'
',
链接:功能(范围){
范围测试=功能(代码){
控制台日志(“详细信息”);
警报(代码);
};
}
}
});
在chrome中,它只能发射一次。可能是Firefox的问题吗?对我来说,Chrome和Firefox都只启动了一次该功能,所以不确定问题出在哪里。一个(可能)不相关的注意事项是,您的HTML标记看起来非常奇怪(在
- 上重复,然后在一个孩子
- 上重复)。介意单独发布模板HTML吗?它在Chrome中为我触发两次