Angular $ broadcast仅在页面刷新后更新 [英] Angular $broadcast only updating after page refresh

查看:87
本文介绍了Angular $ broadcast仅在页面刷新后更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Angular中遇到问题,其中$scope.$broadcast仅在刷新页面一次后才更新监听值:

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

一个控制器:

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

监听器:

$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?

推荐答案

我已经使用$window.location.reload();解决了这个问题,看来我需要重新加载控制器才能重新启动侦听器.

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

这篇关于Angular $ broadcast仅在页面刷新后更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆