在其他页面上观看 rootscope
watch rootscope on other pages
我想在其他控制器中观察 $rootScope 的值,只要它发生变化
场景:
发送响应时位置更改 rootScope 变量的值为 false,当收到响应时它为 true 所以我想在其他控制器上收听 rootscope 的值:
$rootScope.$on('$locationChangeStart', function (event, next, current) {
$rootScope.loadDisp = false;//listen to this
AuthenticationService.Login(function (_data) {
$rootScope.loadDisp = true;//listen to this
})
subcontroller.js
angular.module('acf')
.controller('homeController', function _ctrl($scope $rootScope) {
$scope.$watch('$rootScope.loadDisp', function(newValue, oldValue) {
console.log('*********8888')
ctrl.pageView = $rootScope.loadDisp;
console.log(ctrl.pageView)//only runs first time not second time
});
您正在收听(观看)错误的活动。
$rootScope.$watch('loadDisp', function (newValue, oldValue) {
console.log('*********8888')
ctrl.pageView = $rootScope.loadDisp;
console.log(ctrl.pageView) //only runs first time not second time
});
我想在其他控制器中观察 $rootScope 的值,只要它发生变化
场景: 发送响应时位置更改 rootScope 变量的值为 false,当收到响应时它为 true 所以我想在其他控制器上收听 rootscope 的值:
$rootScope.$on('$locationChangeStart', function (event, next, current) {
$rootScope.loadDisp = false;//listen to this
AuthenticationService.Login(function (_data) {
$rootScope.loadDisp = true;//listen to this
})
subcontroller.js
angular.module('acf')
.controller('homeController', function _ctrl($scope $rootScope) {
$scope.$watch('$rootScope.loadDisp', function(newValue, oldValue) {
console.log('*********8888')
ctrl.pageView = $rootScope.loadDisp;
console.log(ctrl.pageView)//only runs first time not second time
});
您正在收听(观看)错误的活动。
$rootScope.$watch('loadDisp', function (newValue, oldValue) {
console.log('*********8888')
ctrl.pageView = $rootScope.loadDisp;
console.log(ctrl.pageView) //only runs first time not second time
});