类似答案:
这是一个小矮人:http
://plnkr.co/edit/ziU8d826WF6SwQllHHQq?p=preview
app.directive("myDir", function($compile) { return { priority:1001, // compiles first terminal:true, // prevent lower priority directives to compile after it compile: function(el) { el.removeAttr('my-dir'); // necessary to avoid infinite compile loop el.attr('ng-click', 'fxn()'); var fn = $compile(el); return function(scope){ fn(scope); }; } };});
更清洁的解决方案-完全不使用
ngClick:
矮人:http
://plnkr.co/edit/jY10enUVm31BwvLkDIAO?p=preview
app.directive("myDir", function($parse) { return { compile: function(tElm,tAttrs){ var exp = $parse('fxn()'); return function (scope,elm){ elm.bind('click',function(){ exp(scope); }); }; } };});
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)