问题
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!
回答1:
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/
回答2:
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.
来源:https://stackoverflow.com/questions/28117729/save-data-in-json-local-storage-with-angularjs