save data in json local storage with angularjs

流过昼夜 提交于 2020-01-06 12:45:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!