访问$ rootScope和$ scope在`$ rootScope。$ on'内
问题描述:
我需要在URL更改时设置$ rootScope.VARIABLE。
我怎么能在$ rootScope。$回调函数中做到这一点?
$rootScope.$on('$locationChangeSuccess', function(event, absNewUrl, absOldUrl) {
$rootScope.alert =True; // $rootScope is undefined
});
答
用你的代码withing myApp.run上下文。
myApp.run(["$rootScope", "$window", "$location",function ($rootScope, $window, $location) {
\t $rootScope.$on('$locationChangeSuccess', function(evt, absNewUrl, absOldUrl) {
\t \t $rootScope.actualLocation = $location.path();
\t });
\t $rootScope.$on('$locationChangeStart',function(evt, absNewUrl, absOldUrl) {
\t \t $rootScope.actualLocation = $location.path();
\t });
}]);
* “$ rootScope是不确定的” *。这是绝对**不可能**鉴于'$ rootScope。$ on'工作。 – dfsq