我是不是漏掉了什么?
难道我不能从模板 ng-click
访问函数 showHelp()
吗?
我已经为此奋斗了几个小时,但我做不对
angular.module('starter.directives', [])
.directive('errorMessage', function() {
return {
restrict: 'E',
require: '^form',
scope: true,
template:'<button ng-click="showHelp()" class="button icon ion-android-alert button-outline button-assertive"></button>',
link: function(scope, element, attrs, formCtrl) {
scope.showHelp = function(){
console.log('hello');
}
}
};
});
最佳答案
您的代码没有任何问题。我猜你只是忘了在 HTML 中包含该模块。看起来像的东西
<div ng-app="starter.directives">
....
</div>
Here's您的代码在 jsFiddle 中正常运行
关于javascript - 调用指令中隔离范围内定义的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36106670/