You can do that, but then your parent controllers are acting like a service from the previous example. If you have a lot of sibling child controllers keeping state in the parent controller, then your parent controller is going to have a lot of data that does not pertain to it.
I have looked at ui-router, but ui-router doesn't handle the state of not refreshing sibling states/controllers on the page. I also heard the angular team is going to base the next version off of ui-router, which is a good. On Friday, January 24, 2014 7:04:17 AM UTC-8, Paul Spaulding wrote: > > You could also setup a parent view and controller with child controllers > and views for both /payments and /settings. The parent controller could > maintain state while allowing the child controllers to reinitialize as > angular wants to behave. The child controllers can see the parent $scope > variables, and the parents and children can send messages between them > using $broadcast and $emit. > > On Thursday, January 23, 2014 2:58:58 PM UTC-5, jonr wrote: >> >> This is just to brainstorm some things; let me know if I'm crazy and on >> the wrong path of thinking. So I have /payments and /settings as routes as >> an example. I go to /payments and the payments controller loads with the >> view. I go to /settings and the settings controller loads with the view. I >> go back to /payments and again the controller reloads with the view. >> Everything in the controller is reinitialized, but this controller is being >> used no where else in the application. So what do we do? We cache the data >> being returned in ajax calls in a service and if they reload the controller >> the service will check to see if it is already cached and if it is return >> the cached values. Another thing is if I am trying to keep track of state >> in that controller I need to store more data in the service. So now for the >> payments controller I have a payments service which is responsible for >> making all the payments related ajax calls and for caching data that the >> controller would need to keep track of state. >> >> I feel like there should be an option to cache controllers than to always >> reinitialize them because then you don't have to cache data in services you >> are using for controllers and reinitialize the controllers every time. >> >> If I press the back button, I'm going back to a previous state in the >> application. It seems weird that going back will actually reinitialize the >> controller and the data being displayed on the page could be different >> (this case would happen if you aren't caching everything in the service). >> >> Let me know what you guys think. >> >> Jon >> >> -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/groups/opt_out.
