1
我创建了一个指令,当点击按钮添加到指令级别时,添加一行表格 - 更确切地说,是最后一列的按钮。我想,当一个用户点击此按钮,一个方法是在我的控制器,然后调用Angularjs ng-click不会触发指令
myapp.directive("newCandidat", function() {
return {
restrict : "E",
template : "<tr>"+
"<td><input class='form-control' value='' disabled='disabled'></td>"+
"<td><input class='form-control' value='' disabled='disabled'></td>"+
"<td><input class='form-control' value=''></td>"+
"<td><button ng-click='method()'>click</button></td>"+
"</tr>",
replace: true,
transclude:true,
terminal: true,
scope:{method:'&'},
link: function(scope, element, attrs) {
console.log(element);
}
};
});
myapp.controller("Controller",function($scope,$compile){
$scope.addCand=function(){
angular.element($("#candList")).append($compile("<new-candidat method='clickMe()'><new-candidat>")($scope));
}
$scope.clickMe=function(){
console.log("Click me");
}
});
你能告诉我在巫婆的情况下,我们使用终端吗? – Drame
可能有些情况需要控制编译时间。看看这些链接: https://stackoverflow.com/questions/18969610/why-use-terminal-true-instead-of-removing-lower-priority-directives https://stackoverflow.com/questions/ 15266840 /如何理解的最终端的指令性 –