ディレクティブのレベルに、より正確には最後のカラムのボタンを追加するために、ボタンをクリックしたときにテーブルの行を追加するディレクティブを作成しました。私は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 /指示の終わりを理解する方法 –