我想在13号角发送邮件请求.第一个请求响应返回我想在第二个请求中发布的id



我想在angular 13中发送post请求。第一个请求响应返回我想在第二个请求中发布的id,然后我想在第一个发布请求中发送的响应。现在我非常困惑如何使用管道和切换映射。目前我正在嵌套订阅,但问题是第一个帖子的id被分配了,但第二个帖子返回未定义,尽管当我签入日志时,日志值是以对象形式存在的。这可能是什么问题。附件是我的代码:

this.headOffice.createOffice(数据(.订阅((res(=>{这个_officeId=res.id//这是有效的this.submite=true;console.log(this.submited(;

console.log('Response Office '+JSON.stringify(res));
const officeAddress = this.setOfficeAddress();
this.headOffice.createOfficeAddress(officeAddress)
.subscribe(
(resp) => {

console.log('response from office Address ' +resp);//this shows object with id
this._officeAddressId=resp.id; //this gives undefined here is the error
console.log(this._officeAddressId);            
const officeContact = {
active: true,
userId: 0,
dbName: null,
apiStatus: "string",
id: 0,
officeAddressId: this._officeAddressId,
contactTypeid: 1,
countryAreaCode: "string",
contactNumber: this.contact,
extention: this.headOfficeInfo?.ext,
contactTypeName: "string"
}
this.headOffice.createOfficeContact(officeContact)
.subscribe(
(respp) => {
console.log('response from contact ' + respp);
//move to new form
this.submited = true;
}
)
}
);
});
return true;[![Code image file][1]][1]

请帮助我,因为我没有资源指导我

链接HTTP调用是用switchMap完成的,如下所示:


this.headOffice.createOfficeAddress(officeAddress).pipe(
map(res => ({
active: true,
userId: 0,
dbName: null,
apiStatus: "string",
id: 0,
officeAddressId: res.id,
contactTypeid: 1,
countryAreaCode: "string",
contactNumber: this.contact,
extention: this.headOfficeInfo?.ext,
contactTypeName: "string"
})),
switchMap(param => this.headOffice.createOfficeContact(param)),
tap(() => this.submitted = true)
)

最新更新