get parent state from ui-router $stateChangeStart

ぃ、小莉子 提交于 2019-12-25 01:19:19

问题


I want to access the name of the parent state when detecting a statechange. My code so far:

app.run(function($rootScope, $state, authProvider) {
    $rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) {
        console.log(toState.name);
    });
});

Returns [parentState.childState]. One possibility would be to use regex to replace every symbole that comes after the "." but I guess there has to be a function in ui-router to get the name of the parent state.

What would I have to add? to get [parentState]?

Example: The user comes from the state login to the state pets.dogs. pets is an abstract parent state, dogs is a child of it. fromState.name would return login but I want pets.

EDIT: Yes, the workaround toState.name.split(".")[0] is possible but only works under controlled conditions.


回答1:


I think you can do toState.parent.name.



来源:https://stackoverflow.com/questions/36864460/get-parent-state-from-ui-router-statechangestart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!