Angular 4接收SOAP对象并分配给对象

时间:2017-09-23 10:35:40

标签: angular web-services soap angular4-httpclient

我对Angular 4很新,并且正在开发一个项目,该项目从SOAP API接收一个对象(Sale,Invoiceto),并推送到一个对象,并从输入字段中分配值,然后将其发送回SOAP API。 / p>

加载页面时,它会从界面初始化对象:

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 Error:

“无法获取属性的值'构造函数&#39 ;:对象为null或未定义”

但是,如果我在Sale对象中指定值,如:

this.Sale = {"InvoiceNo":"1234567", "InvoiceTo":this.invoiceto, "DeliverTo":this.deliverto}

它不会抛出错误并起作用。

有没有办法在一行中为this.Sale分配所有值?

1 个答案:

答案 0 :(得分:0)

将Sale界面定义为:

interface Sale {
  InvoiceNo?: string;
  InvoiceTo?: any;
  DeliverTo?: any;
}