Summary :
I have a form in view(first
) of my angular application and on success response from the ajax call on submit it redirects the user to the view(second
). There is only one controller for the application(for all view
). Here, user can enter the fields in the form from the view(first
) which should get displayed on the view(second
) & again there is a form in the view(second
) where user can enter the fields in the form which should get displayed on the view(third
).
As all the views(first,second,third
) sharing the same controller function.I created one service
to set
&
get
the data from one view to another and use this service across the application to send the data from one view to another view sharing the same controller.
Problem statement :
I am not able to store each form data in a separate variable as i am getting the data from the same service across the whole application.
Diagram :
As services are singletons in angular. So they won't be recreated when you go to another page.So, when i call a dataService.setData()
method from the controller it removes the previous stored data in the service and updated with new one which creates a problem for me. I want to store all views data separately instead of override with each other.
In you controller create some keys for each different view, lets say:
and when you call the
setData
method, receive thedata
to be stored and thekey
, lets sayand update your
getData
so you can choose which data you want to get like thisNow your dataService must be like this: