0
아래 그림처럼 내가 자동으로 문자열로 객체에서 변환 배열을 저장하려고하면, 로컬 스토리지를 사용하여 이온에 문제가있어
수있는 사람 도와주세요? 사용중인 코드는 다음과 같습니다.
angular.module('mainApp')
.factory('cartFactory', function() {
var cart = [{
'title': 'titre2',
'pic': './img/catalogue/k2.jpg'
}];
console.log("Type 1:" , typeof(cart));
console.log("Content 1:" , cart);
window.localStorage.setItem('cart', cart);
var cart = window.localStorage.getItem('cart');
console.log("Type 2:" , typeof(cart));
console.log("Content 2:" , cart);
return {
all: function() {
return cart;
},
get: function (index) {
return cart[index];
},
add: function (product) {
cart.push(product);
},
remove: function (product) {
var index = cart.indexOf(product);
cart.splice(index, 1);
}
};
});
고마워요!
감사합니다! 너무 간단했다. – fzwael