ui-router >= 1.0.0 get $transition FROM and TO

时间:2021-08-06 19:38:16

In previous versions I've used $rootScope event:

在以前的版本中,我使用了$ rootScope事件:

$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){}

Pretty straightforward approach.

非常简单的方法。

But now I'm forced to use new $transition service. So for generic info I'm writing:

但现在我*使用新的$ transition服务。所以对于我写的通用信息:

$transitions.onStart({}, function(to, from){
    console.log(from.router.globals.current.name);
    console.log(to.router.globals.current.name);
});

from is always empty and to.router.globals.current.name is it really correct way to get a state name now? :D

from总是空的to.router.globals.current.name现在获取州名是否真的正确? :d

So, how I can get from and to names?

那么,我怎么能得到名字?

1 个解决方案

#1


1  

You should be able to get the from and to like this:

你应该能够得到这样的:

$transitions.onStart({}, function(transition){
    console.log(transition.from());
    console.log(transition.to());
});

#1


1  

You should be able to get the from and to like this:

你应该能够得到这样的:

$transitions.onStart({}, function(transition){
    console.log(transition.from());
    console.log(transition.to());
});