Angular UI Router Nested State resolve in child states

后端 未结 2 890
花落未央
花落未央 2020-11-27 05:34

In an angular app I\'m working on, I\'d like there to be an abstract parent state which must resolve certain dependencies for all of its children\'s states. Specifically, I\

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 05:52

    Real Short answer is use:

    $rootScope.$on("$stateChangeStart")

    to listen for any scope changes and do appropriate actions.

    Longer answer is, check out the fiddle: http://jsfiddle.net/jasallen/SZGjN/1/

    Note that I've used app.run which means i'm resolving the user for every state change. If you want to limit it to state changes while authRoot is in the parentage, put the check for $stateChangeStart in the authRoot controller.

提交回复
热议问题