问题在于:
onSubmit() {
var config = {
headers: {
'Content-Type': 'application/json;charset=utf-8;'
}
}
this.http
.post(this.getHostUrl(), JSON.stringify(this.model), config).subscribe();
this.loanAdded.emit(true);
}
这个
this.http.post
this.loanAdded.emit
是同步的。
这个
将在您收到来自的响应之前运行
这是http.post
. 因此,要修复它,请编写
这个
subscribe
块大概是这样的:
onSubmit() {
var config = {
headers: {
'Content-Type': 'application/json;charset=utf-8;'
}
}
this.http.post(this.getHostUrl(), JSON.stringify(this.model), config)
.subscribe(() => this.loanAdded.emit(true));
}
有了这个,你只会在收到你的POST呼叫的响应后发出信号。因此,您将确保后端上的数据已更新。