Angularjs 在其他页面上查看rootscope
我想在其他控制器中观察$rootScope的值,当它被更改时 情景: 发送响应时在位置更改时rootScope变量的值为false,收到响应时为true,因此我想在其他控制器上侦听rootScope的值:Angularjs 在其他页面上查看rootscope,angularjs,angularjs-scope,Angularjs,Angularjs Scope,我想在其他控制器中观察$rootScope的值,当它被更改时 情景: 发送响应时在位置更改时rootScope变量的值为false,收到响应时为true,因此我想在其他控制器上侦听rootScope的值: $rootScope.$on('$locationChangeStart', function (event, next, current) { $rootScope.loadDisp = false;//listen to this AuthenticationS
$rootScope.$on('$locationChangeStart', function (event, next, current) {
$rootScope.loadDisp = false;//listen to this
AuthenticationService.Login(function (_data) {
$rootScope.loadDisp = true;//listen to this
})
subcroller.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
});
我认为您需要一个服务来存储该变量,并在值更改时
$broadcast
一个事件