kamal
kamal

Reputation: 27

How can I access controller in angular directive

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

Answers (1)

Subash
Subash

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

Related Questions