Angularjs ng-click 不会在指令内部触发

Angularjs ng-click doesn't fire inside directive

我创建了一个指令,当单击按钮添加到指令级别时添加一行 table - 更准确地说是最后一列的按钮。我希望当一个人点击这个按钮时,我的控制器中有一个方法,然后调用

    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"); 
        }
    });

这有点令人惊讶,但它在没有 terminal: true 的情况下仍然有效。 terminal:true 似乎停止编译指令的模板,即使它是应用于元素的唯一指令。看看这个 plnkr 看看它是否有效。

来自docs

terminal

If set to true then the current priority will be the last set of directives which will execute (any directives at the current priority will still execute as the order of execution on same priority is undefined). Note that expressions and other directives used in the directive's template will also be excluded from execution.

这也被报道了 here

你需要terminal: true吗?如果是这样,您的指令可能必须编译其内容。查看