1

How can I invoke a function via an directive attribute without isolated scope. I know that it possible with $parse and link.

For example:

<my-directive on-start="foo(query)> </my-directive> 

And I want to invoke the function in the controller.

Thanks

1 Answer 1

3

With scope.$eval:

directive('myDirective', function() { return { link: function(scope, element, attrs) { element.on('click', function() { scope.$eval(attrs.onStart); }); } } }); 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer. In the directive I have an input text and a button, I want that the onStart fund will start before the function of the button clicked (and not when click the element).
Then just take the scope.$eval out of the element.on block. It will run immediately as the directive is evaluated.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.