B
B
bullyy2016-02-16 16:00:57
Angular
bullyy, 2016-02-16 16:00:57

How to properly track data changes in the service?

Data from the service is used in various directives and controllers, how to track changes correctly? All through watch ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
_
_ _, 2016-02-16
@AMar4enko

https://github.com/rubenv/angular-tiny-eventemitter
In services, create methods like onUserChanged that accept a callback and subscribe it to the event.
In controllers do something like

Auth.onUserChanged(function(newUser) {
  vm.user = newUser;
});

L
lega, 2016-02-16
@lega

You can use eventemitter, or pubsub
The directive, in theory, should not go directly to the service, the controller should go to the service and pass it to the directive (although there are exceptions)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question