When using angular ui-router, the fromState
parameter returns an empty object while the toState
works just fine, i would like to access fromState.name
. My ctrl looks like this:
当使用angular ui-router时,fromState参数返回一个空对象,而toState工作正常,我想访问fromState.name。我的ctrl看起来像这样:
.controller('MainCtrl', function ($rootScope) {
// State change start
$rootScope.$on('$stateChangeStart', function (event, toState, fromState){
console.log(fromState); // -> Object {url: "/program", templateUrl: "views/program.html", resolve: Object, name: "program"}
console.log(toState); // -> Object {} when clicking on e.g. 'news'
});
});
1 个解决方案
#1
5
I think you are missing some arguments in your stateChangeStart function. The toParams and fromParams specifically. Check the docs for that callback again. What you have named fromState is probably really toParams, and if the state has no params, thats why it is empty.
我认为你在stateChangeStart函数中缺少一些参数。具体而言,toParams和来自Params。再次检查该回调的文档。你从fromState命名的可能真的是帕拉姆斯,如果国家没有参数,那就是为什么它是空的。
#1
5
I think you are missing some arguments in your stateChangeStart function. The toParams and fromParams specifically. Check the docs for that callback again. What you have named fromState is probably really toParams, and if the state has no params, thats why it is empty.
我认为你在stateChangeStart函数中缺少一些参数。具体而言,toParams和来自Params。再次检查该回调的文档。你从fromState命名的可能真的是帕拉姆斯,如果国家没有参数,那就是为什么它是空的。