1

I have a screen that is made up of 1 state and many nested views in that state

state 1:
    view 1:
        view 1.a:
        view 1.b:
        view 1.c:
    view 2:
    view 3:
        view 3.a:
        view 3.b:
    view 4:

Each view and sub view has its own controller and its own resolved data. How can I tell a view or subview to reload its controller and resolved data without reloading the rest of the views? If that is not possible, how should the application be structured?

I looked into using states and child states, but could not figure out how to get them all to load when the parent state was triggered.

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
Doug S.
  • 682
  • 1
  • 10
  • 26
  • i think you can do that by putting an ng-if on your view.. ng-if removes the element from the dom so it should reset the view .. – MayK May 18 '16 at 13:35

1 Answers1

0

The answer is - hierarchy should be built from states, not via views.

You should really study the doc (which is pretty clear, short and easy to read)

And then maybe follow this:

Nested states or views for layout with leftbar in ui-router?

to see, that we can

  • reload any child state (and trigger its resolves) - without reloading its parent
  • be sure that all views inside of reloaded states are reloaded (each view controller is re-init)

So, the answer should be

split your hierarchy into state hierarchy, not view. Navigate to and among children to change the child views... while profit from parent stable views

Check the plunker here

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • Thanks for taking the time to answer this question. I have read through the documentation but I struggled to implement a state hierarchy for our use case. The problem is that there is really only 1 state. Changing details in one view does not change the context of what the other views are displaying. In some cases data in one view may need to be refreshed because some database operation has occurred, triggered by a different view, but it is not as if we have a list/detail view going on. I was unable to find a way to have all sub-states load based on initial entry into the page. – Doug S. May 18 '16 at 15:33
  • I can hardly argue with you. If you say there is one state.. then one state. But you should not use UI-Router, because it is not working for ONE state scenario. Just a fact.. nothing good or bad. But if you could start to think about it... and you could start to see the hierarchy of views.. that some could change and some could stay if some param is changing... maybe there is a fresh new wind... more states. But only then. And if this could work.. observe my link to LAYOUT example. That could and should give you some ideas. There is a partial view change... triggered by child state change – Radim Köhler May 18 '16 at 15:42
  • I get what you are saying. It is just strange to me that if they give us the flexibility of multiple named views in a state, and allow us to give each named view a controller and the ability to resolve data into those controllers, we should be able to reload those named views. It seems like any dashboard implementation is going to have a problem here. This dashboard of ours is not the only page in the application and we need UI router for the rest of the application. – Doug S. May 18 '16 at 16:13
  • Dashboard would really suite to something else then UI-Router... it is really more about a matrix of settings than a hierarchy of states. Sorry, I do not have better answer... The idea about ng-if is most likely the way to go for you – Radim Köhler May 18 '16 at 16:14