0
我在寫一個自定義指令。我希望該指令添加一個ng-click屬性到元素中 attrs.$set('ng-click','clicked()');
我已經嘗試在編譯函數中添加ng-click指令,並且在鏈接函數之前和之後添加了ng-click。該屬性已添加但不起作用。我很欣賞任何見解。謝謝!在AngularJS中動態添加指令
.directive('myDir', function() {
return{
compile: function (tElement, tAttrs, transclude) {
//tAttrs.$set('ng-click','clicked()');
return {
pre: function (scope, element, attrs) {
//attrs.$set('ng-click','clicked()');
},
post: function (scope, element, attrs) {
//attrs.$set('ng-click','clicked()');
scope.clicked = function(){
console.log('clicked!!!');
};
}
};
}
};
});