2016-04-14 17 views
0

Ich muss $ rootScope.VARIABLE festlegen, wenn sich die URL geändert hat.

Wie könnte ich das in $ rootScope. $ Beim Rückruf tun?

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

* "$ rootScope ist nicht definiert" *. Dies ist absolut ** nicht möglich, da "$ rootScope. $ On" funktioniert. – dfsq

Antwort

0

Verwenden Sie den Code myApp.run Kontext withing.

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 }); 
 
}]);

Verwandte Themen