Bruno Laise
Bruno Laise

Reputation: 117

save data in json local storage with angularjs

I have this form

<form ng-submit="addState()">
            <input ng-model="text1" type="text">
            <input ng-model="text2" type="text">
            <input ng-model="text3" type="text">     
</form>

and this JS

mainAppControllers.controller('DoarScanCtrl', ['$scope', '$routeParams', '$location',
    function($scope, $routeParams, $location){

    }
]);

So First i need save the data in local storage and after this i need have a json

Thank you for any help!

Upvotes: 0

Views: 8441

Answers (2)

micha
micha

Reputation: 1238

I would recommend this lib https://github.com/grevory/angular-local-storage it also auto convert object and array to json

localStorageService.set("model", $scope.model);

$scope.model2= localStorageService.get("model");

i made a fiddle how to use http://jsfiddle.net/jgs4280c/

Upvotes: 1

Jesper We
Jesper We

Reputation: 6097

I have tried several of the available local storage packages and settled for https://github.com/agrublev/angularLocalStorage

It is quite simplistic, but it works very reliably compared to others.

And you can both bind your ng-model directly to the local storage key and then it's done, or you can use legacy style getter/setter where that suits better.

Upvotes: 0

Related Questions