return {
restrict: 'E',
replace: true,
scope: {
cancelFunc: '&'
},
template: '<section class="part-load">'
+ '<p class="part-text">正在加载</p>'
+ '<p class="part-close border-left" ng-click="cancelFunc"></p>'
+ '</section>',
link: function (scope, elem, attrs) {
}
}
}]);
如上,定义了一个指令partload
,期望传入属性值cancelFunc
,绑定ng-click
事件,html结构:
<partload cancel-func="stop()"></partload>
控制器中定义了一个stop
方法:
$scope.stop = function () {
alert(1)
}
Thanks for the invitation
The address of the online example: https://plnkr.co/edit/LBb4dN7...
The only difference from you
ng-click="cancelFunc()"
Thanks for the invitation
I also made an online example: https://embed.plnkr.co/SirYJd...
Try this