1

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.

1 Answer 1

1

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) {}
         };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.