Search code examples
angularjsbroadcastrootscope

Angular $broadcast only updating after page refresh


Hi I have a problem in Angular where $scope.$broadcast is only updating a listening value once the page has been refreshed once:

One controller:

$rootScope.$broadcast('myVar', myValue);

Listener:

$scope.$on('myVar', function(event, myValue) {
    console.log(myValue);
    $scope.myValue= myValue;
});

It works if I refresh the page once, but on initial load the listener is not working? Any ideas?


Solution

  • I have solved the problem, using $window.location.reload(); it appeared that I needed to reload the controller to re-initiate the listener.