我无法在我的TS中调用邮政服务。我正在以一种形式从用户那里获取数据,并将这些数据保存到数组中,并将这些数据显示在表中。之后,我单击另一个按钮以保存我的数据,并调用无法正常工作且未显示任何错误的服务。我还在此按钮上调用其他两个服务,请单击它工作正常,但我的数组服务不起作用。
service.ts
insertAddresses(formData: SettingsAddressesModel) {
return this.http.post(this.apiURL + "/SettingAddress/SaveAddress", formData);
}
component.ts
insertAddressList(compIDforAddress){
for(var i = 0; i < this.childSettingAddressComponent.SettingsAddressesList.length; i++){
this.childSettingAddressComponent.SettingsAddressesList[i].ElementID = compIDforAddress;
//this.addressService.insertAddresses(this.childSettingAddressComponent.SettingsAddressesList[i]);
console.log('address data', this.childSettingAddressComponent.SettingsAddressesList[i]);
}
this.addressService.insertAddressListArray(this.childSettingAddressComponent.SettingsAddressesList);
console.log('Address Elment ID:', compIDforAddress);
}
您需要订阅任何异步的呼叫。否则它们不会执行。
在component.ts
中修改您的代码如下:
this.addressService.insertAddressListArray(this.childSettingAddressComponent.SettingsAddressesList)
.subscribe((result)=>{
// result will contain the response from service
console.log('Address Elment ID:', compIDforAddress);
});
订阅,还会记录错误,如果有的话,帖子方法在大多数情况下默默失败了,如果无法正确处理。
this.addressService.insertAddressListArray(this.childSettingAddressComponent.SettingsAddressesList)
.subscribe((result)=>{
// result will contain the response from service
console.log('Address Elment ID:', compIDforAddress);
},
(error)=>{
console.log("error "+error);
}
);