简体   繁体   English

角度ui路由器中的fromState返回空对象

[英]fromState in angular ui-router returns empty object

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 . 当使用有角度的ui-router时, fromState参数返回一个空对象,而toState运行得很好,我想访问fromState.name My ctrl looks like this: 我的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'

  });

});

I think you are missing some arguments in your stateChangeStart function. 我认为您在stateChangeStart函数中缺少一些参数。 The toParams and fromParams specifically. toParams和fromParams专门。 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. 您命名为fromState的名称可能实际上是toParams,如果状态没有参数,那就是为什么它为空的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM