我正在使用Google Firestore在Angular中异步更新数据,因此我正在使用subscription()通过以下代码流式传输数据:
this.localGame = new Game();
this.game.subscribe(data => {
// @ts-ignore
this.localGame = data.game;
console.log('A');
});
console.log('B');
if (this.localGame.team2.length >= this.localGame.team1.length) {
this.localGame.team1.push(this.playerName);
我希望数据不断地流(我也在更新数据库),但是我还需要至少在“ B”之前打印“ A”,以避免this.localGame.team2被定义。我对这一切都是陌生的,有人可以解释一下是否有一种干净的方法来执行此操作,而又不会造成超时或其他问题吗?