我知道我可以运行:
scope.$watch(someItem, function(){})
但我不能想出一个办法来监视我的应用程序的$state.$current.name
变化。
我知道我可以运行:
scope.$watch(someItem, function(){})
但我不能想出一个办法来监视我的应用程序的$state.$current.name
变化。
它在文档:https://github.com/angular-ui/ui-router/wiki#state-change-events
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams){
// do something
})
这工作:
$scope.$watch(function(){
return $state.$current.name
}, function(newVal, oldVal){
//do something with values
})
这帮助我了指令实现。谢谢! – rahulthakur319
我还要提到的是$ rootScope $上( '$ stateChangeStart')必须放置在根状态的顺序。在每个状态变化中都可用,如果我没有错过 –
我得到'找不到变量:$ rootScope'我需要做什么? – bryan
您需要将$ rootScope注入到您要调用的控制器中。 – Eolis