Hello, i have a problem with localforage. I want to get the value of the item which I have set before. but not as expected.
Here my code:
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
declare var require:Function;
const localforage:LocalForage = require("localforage");
@Injectable()
export class CartServiceNew {
public _cart = [];
public _cart_now: any;
constructor(public http: Http) {
localforage.config({
name: 'LifeRich_APP'
})
}
add(item) {
this._cart.push(item);
localforage.getItem("cart").then((result) => {
let myc: any = result;
if(myc) {
for(let dt of myc) {
this._cart.push(dt);
}
}
localforage.setItem("cart", this._cart);
});
}
list() {
return localforage.getItem("cart");
}
clear() {
localforage.removeItem("cart");
}
}
when I took the value this way:
console.log(cartService.list());
output:
{"__zone_symbol__state":null,"__zone_symbol__value":[]}
Is there something wrong? please help me, thanks