【问题标题】:save data in json local storage with angularjs使用angularjs将数据保存在json本地存储中
【发布时间】:2015-03-22 22:53:46
【问题描述】:

我有这个表格

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

还有这个 JS

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

    }
]);

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

感谢您的帮助!

【问题讨论】:

  • 你要保存到localStorage的数据是什么?

标签: javascript json angularjs local-storage


【解决方案1】:

我已经尝试了几个可用的本地存储包并选择了https://github.com/agrublev/angularLocalStorage

它非常简单,但与其他相比,它的工作非常可靠。

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

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2013-08-17
      • 1970-01-01
      • 2015-12-23
      • 1970-01-01
      • 2016-04-29
      • 2015-10-23
      • 2014-07-07
      • 1970-01-01
      相关资源
      最近更新 更多