Examples on view states


#1

Hello all:

I will greatly appreciate it if someone could point me to tutorials/examples on how to retain the view state when switching views within an app, and also how to exchange states between different controllers.

For example, I have a form that has some values, which I will plot in a different view. I want the plot controller to get data from the form controller, and need to be able to switch between the form, and the chart without losing the data on either of the two.

Thanks a lot in advance for your help.


#2

Hey,

I would use a service or factory, an example: http://stackoverflow.com/questions/13882077/angularjs-passing-scope-between-routes

So, make a service which keeps the data. Since a service is basically a singleton it should fit your case.

I hope this helps, good luck :wink:


#3

@bramslob - Thanks a lot for your response. I already started using services to make my controllers more concise, but will review the link you included in your response to learn how to use the service to retain the view state.

Thanks again, and have a nice weekend.