我对 Angular 4 很陌生,并且正在从事一个从 SOAP API 接收对象(Sale,Invoiceto)的项目,然后推送到一个对象,并从输入字段中分配值,然后将其发送回 SOAP API。
加载页面时,它会从接口初始化一个对象:
this.Sale = {} as Sale;
this.Invoiceto = {} as Customer;
this.Deliverto = {} as Customer;
然后从 SOAP API(InitializeSale) 接收 Sale 对象并覆盖该对象:
this.Sale = response.Sale
它填充 Sale.InvoiceNo。
然后我填充 Sale 对象:
this.Sale['Invoiceto'] = this.invoiceto
this.Sale['Deliverto'] = this.deliverto
并在第二个 API 调用 (SaveSale) 中发送。
在第二个 API 调用中,它返回一个错误 TypeScript 错误:
“无法获取属性‘构造函数’的值:对象为空或未定义”</p>
但是,如果我在 Sale 对象中分配值,例如:
this.Sale = {"InvoiceNo":"1234567", "InvoiceTo":this.invoiceto, "DeliverTo":this.deliverto}
它不会抛出错误并且有效。
有没有办法在一行中将所有值分配给 this.Sale?