我有一个指令:
.directive('directive', [ function () {
return {
restrict: 'AE',
scope: {
value: '=value'
},
link: function(scope, elem) {
$document.bind('click', function() {
...call clickDocument() function
});
},
bindToController: true,
templateUrl: 'item.html',
controller: 'Item as item'
};
}])
该指令的控制器:
.controller('Item', [function Item () {
this.clickDocument() = function() {
console.log('click the document')
}
}])
我想在文档点击事件中从控制器运行clickDocument()
。
我该怎么做?
谢谢。
答案 0 :(得分:0)
您可以将控制器包含在链接注射中。
link: function(scope, elem, attrs, ctrl) {}