AngularJS: $ passing from service doesn't always call listeners on child controllers
I have a service to connect to my server, and after receiving the data, I broadcast the event:
user.getUserData = function () {
var userData = $http.get('/user');
userData.success(function (data) {
currentUser = data
$rootScope.$broadcast(EVENTS.userChanged);
});
userData.error(function () {
user.removeUser();
});
return userData;
};
I also have one main controller set on the body tag and multiple child controllers. On these controllers, I have
$rootScope.$on(EVENTS.userChanged, function () {});
and this function on the main controller is called every time I update the app, but on the child controllers it is only called occasionally. What could be wrong?
+3
source to share
No one has answered this question yet
Check out similar questions: