简体   繁体   中英

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

I know that I can run:

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

But I can't figure out a way to watch over change of $state.$current.name in my application.

It's 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
})

This works:

$scope.$watch(function(){
    return $state.$current.name
}, function(newVal, oldVal){
    //do something with values
}) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM