简体   繁体   中英

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 . My ctrl looks like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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