1

I am currently working with AngularJS. Now I am wondering how can you save data in an html form between routes (angularjs routeprovider)? Does anyone has an example, experience or a link, which can help me to solve this problem?

It would be nice to know, because like that a customer can fill out his personal informations on a page and if he wants to he can switch to an other page. And after that he can return on the same form field, where he stopped writting, with all he's written informations still in the form.

1
  • There are many different approaches to this. For example, you can use a service shared between the different routes, or even Local Storage. A service would probably be the most "Angular" way. Commented Jun 15, 2015 at 18:59

1 Answer 1

1

With what you want is retain the form data on a page even when you have navigated away and then came back.

There are 2 approaches to achieve this.

  1. Local Storage - Store information in local storage, on the form page, update scope based on the information stored in local storage.
  2. $rootScope - Store information in root scope. No change required in controller. The negative things being, information will be lost on page refresh and it is not recommended to store page specific information in root scope.
Sign up to request clarification or add additional context in comments.

4 Comments

Additionally, you can also use service as suggested by @Boaz
How can you store the inputted data as a java object? Mine is coming back as null.
Html home page, has a input box. How to save users input as an java object
@Jesse - Are we mixing up java and javascript here? If you need in javascript, create an object with key value pair or if it is a form and you are using jquery use serialize function. If the question is beyond this, then please post it as another question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.