K
K
kMotion2017-10-23 14:35:18
Angular
kMotion, 2017-10-23 14:35:18

Angularjs communication between directives, method call?

Hello everyone, please tell me, there are two directives, each has a controller that has its own methods. Directives not nested within each other. Just following each other. What method can be used from the controller of one directive to call the method of another directive? Pass method to be called in scope? What is the method to do this? Perhaps there is an article to read? Specify the direction where to dig. Thanks for answers.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Mazhekin, 2017-10-23
@kMotion

three different ways
1) send a $broadcast event, catch it $on in the directive and call the desired function
2) embed an object with a function pointer through the attribute (bindings, '<', '='), var commander = { func: finction() {} }, inside the directive redefine the function commander.func = function () { here is my code... }, and call it from outside or in another directive commander.func();
3) it is better to place the code of the directive method, separately in the service, and call the service method in another directive, if the situation allows, and always design the application this way.

K
kMotion, 2017-10-23
@kMotion

thanks, used method 1. Everything works. Are there no other methods? Can transfer one delegate to another or is it already a perversion?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question