im working in a app that makes many calculations, and basically i implemented a functionality when a user refreshed or F5 a page he will not loose his data in the current page, im saving the data in localStorage since the data isnt saved in the db, does angularjs have some kind of storage data that i could use it or does anybody no a better solution to use. (not using a database).
3 Answers
You can use the following ways for storing the data:
1) $localStorage 2) $sessionStorage
Given below is a simple example of how you can save an input field in localStorage and still retrieve the value on refresh
<input type="text" ng-model="myValue">
<button type="button" ng-click="saveData()">Save</button>
In controller:
//this will execute everytime on refresh
$scope.myValue = $localStorage.data || null;
$scope.saveData = function(){
$localStorage.data = $scope.myValue;
//similarly $sessionStorage.data can be used
}

- 4,503
- 1
- 16
- 24
-
Thanks Rahul, one last question, im getting the error "Failed to execute 'setItem' on 'Storage': Setting the value of exceeded the quota.", but the strange part is in the first load works fine, but after loading again i get this error, any advice? – Marco Santos Jun 29 '16 at 19:26
-
What exactly are you doing? Also can you check your console under resources and delete all the localStorage that you have. Also, see if this can help http://stackoverflow.com/questions/23977690/local-storage-in-chrome – Rahul Arora Jun 29 '16 at 19:30
You could choose between localStorage and sessionStorage.
localStorage will keep data until you will decide to clear it programmatically, or user will clear it in browser.
sessionStorage on other hand will be cleared when browser or tab is closed. Sometimes it's better solution, because you won't need to think about situations when you would have to clear localStorage.

- 2,090
- 1
- 13
- 11
you can use localstorage for this which an html5 api
Or
If you want to do it with angular then you better go through the following link
https://github.com/grevory/angular-local-storage
http://gregpike.net/demos/angular-local-storage/demo/demo.html

- 871
- 5
- 12