[英]Angular 5 - Two way data binding not working
我不明白...我想對我的服務進行獲取請求,該請求為我提供了我掃描的條形碼的特定硬件-已經可以使用。
我將正確的硬件作為對象拿回,看起來像這樣->
但是,如果我現在想顯示此對象,則只會在前端獲得[object Object]
。
component.html
{{ terminal }}
component.ts
terminal: any[] = [];
constructor(private terminalService: TerminalService) { }
this.terminalService.getTerminalByBarcode(barcode).subscribe(terminal => {
console.log(terminal.terminal);
this.terminal = terminal.terminal;
});
我已經嘗試過使用terminal: Object;
但這並沒有改變任何東西。 希望有人可以告訴我,我認為雙向數據綁定有何錯誤?
如果terminal.terminal
是一個對象,則{{ terminal }}
的輸出可以是[object Object]
,因為它在該對象上調用toString
。
要查看terminal
的結構,可以使用json
管道
{{ terminal | json }}
這是因為在您的視圖中,您試圖輸出實際的對象.toString。
您需要輸出對象屬性,如下所示:
{{ terminal.barcode }}
{{ terminal.dateArrival }}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.