Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ng2.UIRouterConfig): Allow new UIRouter() to finish before config…
…uring it Execute `.config()` in a setTimeout() to allow the UIRouter constructor to fully complete.
- Loading branch information
a151f71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes some issues for me: In Angular2 when bootstrapping a component with the router the component is loaded fully before my states are registered, so that all of the hrefs on the ui-sref directive turn up as "null"
a151f71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as this #2912 ?
Are your
uiSref
inside a routed component (uiView
) or inside the root component?a151f71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's inside of the root component so might be that issuse - i've stepped through the code and the states aren't yet defined when my Component loads so the href resolving fails.
Quite new to Angular2 so problem might be that i'm not fully grasping the change detection yet - is there any way to listen to newly registered states? I've gone through the StateRegistry code but couldn't find any Observable or Event that I could listen to. Would allow to simply recreate the uiSrefs once the configuration is finished or has changed (maybe this is even the more desirable option).
a151f71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean.
There isn't (yet) an event when a state is registered. I think it would be a good addition to the StateRegistry API.
a151f71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also 100% sure that this is causing the issue you linked, if you go into the plunker, set a breakpoint before the setTimeout and paste
setTimeout = (f) => { f() }
into the dev console the hrefs work fine.I don't know the motivation for this feature, if it is to be kept i suppose to fix one could implement an Event/Observable for the StateRegistry and make uiSref and similar directives subscribe to it
a151f71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A workaround is to bootstrap a
UIView
, instead of your custom root element.