2015-09-25 44 views
0

我希望使用ngStorage存儲一個數組以滿足持久性數據需求。這裏是我的代碼:在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}); 
    } 
}) 

我需要的物品數組存儲在ngStorage

+1

請閱讀文檔https://github.com/gsklee/ngStorage –

+0

你嘗試使用ngStorage了嗎?你的問題到底是什麼? –

回答

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)); 
    } 
});