Angular $broadcast only updating after page refresh

强颜欢笑 提交于 2019-12-11 20:20:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!