我希望使用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
中答案 0 :(得分: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));
}
});