【发布时间】:2017-11-01 14:35:52
【问题描述】:
我创建了一个指令,当单击按钮以添加到指令级别时添加一行表格 - 更准确地说是最后一列的按钮。我希望当单击此按钮时,我的控制器中有一个方法,然后调用
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");
}
});
【问题讨论】:
标签: angularjs directive angularjs-ng-click