I got the value in the id variable as promise but .then
is not responding. Why?
private getServer()
{
return this.db.list('/shopping-carts/').snapshotChanges().toPromise();
}
private async getOrCreateCartId() //to create a cartid or acceess the cartid
{
let cartId = localStorage.getItem('cartId'); //to create a cartid or acceess the cartid
if(cartId)
{
return cartId;
}
this.id = this.getServer()
.then(result => {
console.log('From Promise:', result);
this.cartIdFire = result;
});
console.log(this.id);
console.log(this.cartIdFire);
if(this.cartIdFire)
{
return this.cartIdFire;
}
}
I am trying to get the value in the cartIdFire
, but .then function is not responding. I got the value in the id variable as a promise, though.
i edited this yet this isn't working
private async getOrCreateCartId() //to create a cartid or acceess the cartid
{
let cartId = localStorage.getItem('cartId'); //to create a cartid or acceess the cartid
if(cartId)
{
return cartId;
}
this.id = await this.getServer();
this.id.then(x => this.cartIdFire = x);
console.log(this.id);
console.log(this.cartIdFire);
if(this.cartIdFire)
{
return this.cartIdFire;
}
}
even now all method of my service stopped and cartIdFire is undefined till now
I am new to angular. how do i can set cartIdFire? i see the suggested question but I did not understand anything