Answer the question
In order to leave comments, you need to log in
How to work with events (events) in AngularJS?
I started to pick Angular, and a question arose about events. What to do if you need to communicate with controllers that are not subordinate to each other? For such cases, there is emit and broadcast, as I understand it, but what if the controllers are equal? Hang on rootScope or create one parent controller and work through it? Tell me about the architecture, please.
Answer the question
In order to leave comments, you need to log in
You can organize communication simply through scopes.
You can place the creation in a service.
The main thing is to make sure that when you destroy your two controllers, the one created earlier is also destroyed in order to avoid memory leaks. (If necessary throughout the life of the application, create a new scope from $rootScope
)
Yes, if you do not clean up after yourself, it will be bad. But angular, at least the latest versions, took care of memory leaks, took care of it, and if you remove the scope, then all event listeners are removed.
those. create a service with an event manager and inject the service into the controllers?
jsfiddle.net/simpulton/GeAAB found how through rootScope, is this normal?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question