问题
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:
I have solved the problem, using $window.location.reload();
it appeared that I needed to reload the controller to re-initiate the listener.
来源:https://stackoverflow.com/questions/27122736/angular-broadcast-only-updating-after-page-refresh