How to $ watch the state change of $ stateProvider in AngularJS?

I know I can run:

scope.$watch(someItem, function(){}) 

But I cannot find a way to observe the change of $state.$current.name in my application.

+47
angularjs
Feb 18 '14 at 23:13
source share
2 answers

In the docs: https://github.com/angular-ui/ui-router/wiki#state-change-events

 $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){ // do something }) 
+129
Feb 18 '14 at 23:18
source share

It works:

 $scope.$watch(function(){ return $state.$current.name }, function(newVal, oldVal){ //do something with values }) 
+12
Sep 14 '16 at 17:54 on
source share



All Articles