Reputation: 27
I want to access controller in angular directive. How can I do that?
I have a link function in the directive and I want to access the controller passed to the directive.
Upvotes: 1
Views: 35
Reputation: 7266
The link function's 4th parameter gives you access to the controller instance.
return {
template: template,
controller: controller,
controllerAs: 'myCtrl',
restrict: 'E',
replace: true,
link: function(scope, element, attrs, controller) {}
};
Upvotes: 1