2016-04-14 15 views
0

URL değiştiğinde $ rootScope.VARIABLE değerini ayarlamanız gerekiyor.

Bunu, $ rootScope. $ Geri aramada nasıl yapabilirim?

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

* * "$ rootScope tanımsız". Bu kesinlikle ** mümkün değildir ** verilen $ rootScope. $ Üzerinde çalıştı. – dfsq

cevap

0

myApp.run bağlamı içinde bize kodunu kullanın.

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

İlgili konular