我知道我可以跑:
scope.$watch(someItem, function(){})
Run Code Online (Sandbox Code Playgroud)
但我无法想出一种方法来监视$state.$current.name我的应用程序中的更改.
Gab*_*abe 143
它在文档中:https://github.com/angular-ui/ui-router/wiki#state-change-events
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams){
// do something
})
Run Code Online (Sandbox Code Playgroud)
Crh*_*rez 26
这有效:
$scope.$watch(function(){
return $state.$current.name
}, function(newVal, oldVal){
//do something with values
})
Run Code Online (Sandbox Code Playgroud)