AngularJS - 访问控制器内的指令对象
AngularJS - accessing the directive object inside the controller
假设我定义了一个简单的指令:
app.directive('someDirective', [function() {
return {
restrict: 'E',
link: function() {
},
controller: [function() {
// Access directive object here...
}]
}
}]);
我可以在 someDirective
的控制器函数中访问生成的 someDirective
对象吗?我知道 this
属性 引用 compile
和 template
函数内的指令对象,但我不知道如何访问控制器函数内的指令对象。有什么技巧吗?
谢谢。
当然可以,但不确定为什么要...
app.directive('someDirective', [function() {
var directiveObject = {
restrict: 'E',
link: function() {
},
controller: [function() {
// Access directive object here...
directiveObject.whatever
}]
}
return directiveObject;
}]);
假设我定义了一个简单的指令:
app.directive('someDirective', [function() {
return {
restrict: 'E',
link: function() {
},
controller: [function() {
// Access directive object here...
}]
}
}]);
我可以在 someDirective
的控制器函数中访问生成的 someDirective
对象吗?我知道 this
属性 引用 compile
和 template
函数内的指令对象,但我不知道如何访问控制器函数内的指令对象。有什么技巧吗?
谢谢。
当然可以,但不确定为什么要...
app.directive('someDirective', [function() {
var directiveObject = {
restrict: 'E',
link: function() {
},
controller: [function() {
// Access directive object here...
directiveObject.whatever
}]
}
return directiveObject;
}]);