我需要HttpClient.post一个问题并以相同的方式关联命题。我尝试使用Subject.toPromise()和async / await指令。我需要等待Question帖子的回复才能收到Question.id,然后才能发布Proposition。
async getNewQuestionId(): Promise<number> {
const id: number = await this.subjectQuestionId.toPromise();
return id;
}
/* Proposition post, trying to get the ID before sending the post */
async postProposition(proposition: Proposition) {
const questionId = await this.getNewQuestionId();
...
}
/* Question post (callback) */
...
this.subjectQuestionId.next(response.id);
...
该脚本不执行发布建议,并且似乎停止在该行:
const questionId = await this.getNewQuestionId();
但是没有其他事情发生。 主题值会在几秒钟后更新。