Angular $broadcast only updating after page refresh

1.4k Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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