In this scenario, await this.getServer()
will not work, it will not wait to be solved, it only works in Promise, not in Observable, where it is solved within the subscribe
A simple solution would be, in the getServer()
method to convert the Observable to Promise, using toPromise()
and returning this value
private async getServer()
{
return this.db.list('/shopping-carts/').snapshotChanges().toPromise()
}
And get the cartIdFire
in the getOrCreateCartId()
method
this.cardIdFire = await this.getServer()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…