-
Notifications
You must be signed in to change notification settings - Fork 3k
$state.current is sometimes 'empty' #1627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Couldn't reproduce the bug after refactoring some async code. Closing.. |
Just encountered this bug tonight... we could see the proper $state.current values in the HTML but they were not accessible in the corresponding controller. Very strange! |
Same here ~ |
I tried this and it works:
In view:
Or:
In view:
|
Same thing |
This is the root state. This happens when your initial page load targets a nested URL that depends on a resolve. The root state is the initial state of the application pending a successful transition to the desired state. Feel free to add this to the FAQ if it was unclear to you, and you think it might confuse other people as well. |
I don't understand. |
@ddctd143 i think this can help you |
Same thing as @ddctd143 is happening to me. @nateabele what if my state doesn't have a parent and doesn't depends in a resolve?. I'm trying to get the $state.current in a directive, if i set a timeout works as i expect, if not i get the $state object with empty values. How do i wait until $state.current resolve, is there a promise?, Am i approaching this incorrectly? |
I faced the same issue, This is happening when I reload the page. Anyways, I used $timeout and it is working fine for me.
|
I have this bug too. |
|
I faced the same issue, but felt that $timeout is bad.
|
Thanks @last-indigo. This solution works for states, but it doesn't work on with History events. I'll edit my comment if I figure it out. |
+1 Ok with fake timeout. |
@nateabele I understand what you said, but I don't understand how to deal with it. And the FAQ doesn't answer the question... I need to get the current state name from a component's controller to initialise the component accordingly to the current state (when user reload the page for example). But in some cases I've got the |
resolve the target state and use the name as you like |
I encountered this strange bug today. Sometimes (I don't know why) $state.current returns an "empty" object:
There's at least two stackoverflow issues about this bug:
http://stackoverflow.com/questions/25370775/exposing-the-current-state-name-with-ui-router
http://stackoverflow.com/questions/24895908/how-do-return-the-state-current-name-from-ui-router-statechange
I can't explain the bizarre behaviour I'm seeing: When I debug $state I can see that $state.current is fine, but when I print $state.current directly I get this:
$state.$current.self is also the same empty object., even though it looks fine when I inspect $state.
I don't quite understand how this can be happening. How can $state and $state.current return different values? $state.current doesn't have a getter.
EDIT: Okay, the problem was that the debugger doesn't show the object when it was printed, rather it shows it's current state. Now I just need to figure out why the state is empty.
The text was updated successfully, but these errors were encountered: