0

我希望使用 ngStorage 存储一个数组以满足持久数据的需求。这是我的代码:

.factory("items", function () {
    var items = {};
    items.data = [];
    return items; 
 })

.controller('ItemsController', function($scope,items) {
    $scope.items = items;
    $scope.addItem = function (id,item,size,price,quantity) {
        items.data.push({id,item,size,price,quantity});
   }
 })

我需要将 items 数组存储在 ngStorage

4

1 回答 1

0
.controller('ItemsController', function ($scope, items, $localStorage) {
  $scope.items = items;
  $scope.addItem = function (id, item, size, price, quantity) {
    items.data.push({id, item, size, price, quantity});
    localStorage.setItem("items", JSON.stringify(items));  
  }
});
于 2017-06-30T10:53:45.607 回答