Saving controller variables beetwen states



In my app I have multiples tabs of which one have form. When I am switching to another tab form gets cleared. Is there a simple/build-in way to save them? I dont want to use storage yet, because it is only a form.



Use a service for that.

Services/Factories are state-independent.

app.service('helloWorldFromService', function() {
  this.sayHello = function() { return "Hello, World!"; };

It is lika controller - call app.service give it a name.

Declare functions or variables with this.xxxx = .
So you can set up a service with your form values.

this.formData = {};

In your controllers where you fill the form -> include your service and store the data on yourService.formData.




I was thinking of using service/factory, though that it will be over-complicating and there has to be an
easier solution. But yeah will go with that.

If someone has some different approach, you are welcome.


You could write the data on the “rootScope”. But i am not a friend to abuse the rootScope for this.
This is what services are made for ;).