2016-04-14 54 views
0

我需要在URL更改时设置$ rootScope.VARIABLE。

我怎么能在$ rootScope。$回调函数中做到这一点?

$rootScope.$on('$locationChangeSuccess', function(event, absNewUrl, absOldUrl) { 
    $rootScope.alert =True; // $rootScope is undefined 
}); 
+3

* “$ rootScope是不确定的” *。这是绝对**不可能**鉴于'$ rootScope。$ on'工作。 – dfsq

回答

0

用你的代码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 }); 
 
}]);

相关问题