-
Notifications
You must be signed in to change notification settings - Fork 3k
Controller not reloaded when using back button #122
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
As long as you remain within a parent state, and the parameters that belong to that parent don't change, the views and controllers don't get reloaded. This is a feature and is by design, otherwise every single view would be reloaded on every state transition. If you want those views/controllers to be reloaded, declare them in the child state. But you should be able to write the controller so that it can handle child state changes without a reload. |
Hmm I see. Let's say I've defined a parent/root state called : mystate When I click on a grid element, I'm transitioning to a child state : mystate.detail Because there is no controller reload as long as I stay within a parent state, I'm not sure when/how to reload my list. |
Hm, maybe you can directly update the list (which presumably your controller in the parent state binds to the scope) from the child controller? Or the controller could expose a function on the scope to perform the reload, which you call from the child. Listening for $stateChangeSuccess would also be an option -- as your controller only exists as long as it's state is active, you shouldn't receive any events for states that aren't children of the state that owns the controller (you might currently also receive the event for the entry and/or exit into the controllers own state -- the ui-view logic itself is triggered off $stateChangeSuccess at the moment). |
I have a similar setup as @ffesseler. I have a list of items in the mystate, the child mystate.details is for editing/creating a single item. mystate uses resolve to get a list of items, but these are summary data, ie not the full items. mystate.details uses resolve to get the full item for editing. So when saving/updating mystate.details sends the item the and the server and the app transitions back to mystate. So how to get the changed/new item into the mystate list! There are many ways to skin this cat, as already mentioned
Most of these seem to couple mystate.details to mystate, but I may want to reuse the mystate.details controller in another state so I rather it not need to know mystate. I'd rather not keep a reference of the list in a service and I generally keep event usage to a minimum. Also now mystate.details needs to deal with all the async responses to ensure the transition to mystate occurs after the item is in the list, but this is what resolve is supposed to solve. Instead I'd prefer to be able to transition from my state.details to mystate but tell it to re-resolve, and re-create the controller only for mystate. Any comments on if this, is it a feature request or something that makes sense for states and ui-router? |
One option would be to make your 'details' child a sibling of the list state rather than a child, that would give you the reload behaviour you're after. However the ability to force-reload a state has been requested before -- I imagine it will be implemented at some point. Personally I'd probably handle fetching the list and individual details and updating your client-side state in a custom service, rather than burdening the view controllers with all that stuff. |
I think the force-reload feature should be added in the roadmap then :) |
As it was mentioned above, one way (and seems most natural to me) is to refresh parent resolve value of a parent view in a child view. I'm sure there should be some kind of a one-liner to make this pseudo-code work.
Could please someone point me the way out? |
I've some nested views.
When I go back using the browser back button from a child state to its parent state, the parent state controller is not reinstanciated.
Is it normal behaviour? Can I override it ?
The text was updated successfully, but these errors were encountered: