我的代码在将输入值发布到 json api 时遇到问题。请帮助我如何解决“Promise”类型上不存在属性“id”的问题。 抱歉,我只是这里的初学者。提前致谢。
//This is my code on component.ts
async OnNext() {
let newCase = {PersonalInformation:{}, Status:"Pending", LastViewedPage:"personal-info",
CreatedBy: this.User.userId}
newCase.PersonalInformation = this.PersonalInformation.value
const responseData = this.conn.CreateCase(newCase)
if(responseData.id) {
this.router.navigate(['address-info'])
}else{
this.errorDesc = "System error."
}
}
//This is my post code in my service definition.
async CreateCase(data: any) {
return new Promise((success, failed) => {
this.http.post('http://localhost:3000/caseList', data).subscribe(
data => {success(data)},
error => {failed(error)}
)
})
}