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

后端 未结 2 1631
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 10:09

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.nam

相关标签:
2条回答
  • 2020-12-02 10:55

    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
    })
    
    0 讨论(0)
  • 2020-12-02 11:13

    This works:

    $scope.$watch(function(){
        return $state.$current.name
    }, function(newVal, oldVal){
        //do something with values
    }) 
    
    0 讨论(0)
提交回复
热议问题