使用angularjs将数据保存在json本地存储中

时间:2021-11-07 19:41:38

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

而这个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

所以首先我需要将数据保存在本地存储中,之后我需要一个json

Thank you for any help!

感谢您的任何帮助!

2 个解决方案

#1


1  

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

我会推荐这个lib https://github.com/grevory/angular-local-storage它也会自动将对象和数组转换为json

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

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

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

我做了一个小提琴如何使用http://jsfiddle.net/jgs4280c/

#2


0  

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

我已经尝试了几个可用的本地存储包,并已安装为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.

您可以将ng-model直接绑定到本地存储密钥,然后完成,或者您可以使用更适合的传统样式getter / setter。

#1


1  

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

我会推荐这个lib https://github.com/grevory/angular-local-storage它也会自动将对象和数组转换为json

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

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

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

我做了一个小提琴如何使用http://jsfiddle.net/jgs4280c/

#2


0  

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

我已经尝试了几个可用的本地存储包,并已安装为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.

您可以将ng-model直接绑定到本地存储密钥,然后完成,或者您可以使用更适合的传统样式getter / setter。