2015-09-25 4 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)); 
    } 
}); 
Смежные вопросы