S
S
Stepan Kormilin2015-12-04 13:02:01
Angular
Stepan Kormilin, 2015-12-04 13:02:01

Is it possible to get the value of a variable from a directive in a controller?

Good afternoon!
The scope.directiveVar variable is declared in the directive. In the controller, I need to get the value of this variable. A directive from a third-party module that is injected as a dependency to the main application module. Is it possible to do so?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nicholas, 2015-12-04
@healqq

It is best to use the pub/sub pattern in this case.
Angular uses $broadcast , $emit , $on functions for this .
Here's a good article about the difference between broadcast and emit and how it works in general: toddmotto.com/all-about-angulars-emit-broadcast-on...

L
lega, 2015-12-04
@lega

In the directive, there are "operators" = and & (in scope) for this. But if the directive is not provided, then it will have to be edited.
You can also do a dirty hack - climb into child scopes and take a variable from there (or subscribe to it).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question