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
angularjs


source to share


No one has answered this question yet

Check out similar questions:

3178
AngularJS: Service vs provider vs factory
912
'this' vs $ scope in AngularJS controllers
828
AngularJS: Preventing $ digest error is already being executed when calling $ scope. $ Apply ()
528
Can one controller call another?
496
Fighting AngularJS controller twice
429
AngularJS: Initializing a Service with Asynchronous Data
333
AngularJS accessing parent scope from child controller
179
Call AngularJS from legacy code
170
AngularJS: Factory and Service?
155
AngularJS: the correct way to bind to service properties



All Articles
Loading...
X
Show
Funny
Dev
Pics