2017-09-23 117 views
0

我對Angular 4非常陌生,並且正在處理一個項目,該項目從SOAP API接收對象(Sale,Invoiceto),並推送到對象,並從輸入字段分配值,並將其發送回SOAP API。Angular 4接收SOAP對象並分配給一個對象

當頁面被加載它初始化從一個接口的對象:

this.Sale = {} as Sale; 
this.Invoiceto = {} as Customer; 
this.Deliverto = {} as Customer; 

然後接收來自SOAP API(InitializeSale)出售對象和覆蓋對象:

this.Sale = response.Sale 

和它填充塞爾。發票號碼。

然後我填充銷售對象:

this.Sale['Invoiceto'] = this.invoiceto 
this.Sale['Deliverto'] = this.deliverto 

,並在第二API調用(SaveSale)發送。

在第二API調用它返回一個錯誤打字稿錯誤:

「無法獲取屬性‘構造’的值:對象爲null或undefined」

但是,如果我在銷售賦值這樣的對象:

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

它不會拋出錯誤和工作。

是否有任何方法可以將所有值分配給this.Sale在一行中?

+0

是銷售的接口或類?你能分享它的代碼嗎? – golfadas

+0

這是一個使用接口的對象銷售 – user2315153

+0

如果銷售有接口客戶它應該被定義爲'this.Sale = {}作爲客戶;'' – golfadas

回答

0

定義售接口:

interface Sale { 
    InvoiceNo?: string; 
    InvoiceTo?: any; 
    DeliverTo?: any; 
} 
相關問題