[英]Angular 2 two way data binding not working
我在使用自定義雙向數據綁定以在Angular 2中工作時遇到了麻煩。文檔顯示盒子模型中的香蕉-[()]只是合成糖,但是在我的示例中,這種方式行不通,而且時間更長方法有效:
<child-component [(test)]="check">This child updates only itself</child-component>
<child-component [test]="check" (check_send)="check=$event">This child updates all</child-component>
@Output事件不會更改框模型(第一行)中香蕉中的父值。 當第二行工作時,我看不到我在做什么錯。 這是文檔的鏈接: https : //angular.io/guide/template-syntax#two-way-binding---
這是我創建的用於展示此行為的插件: https ://embed.plnkr.co/eTfkQmRfBRxeKCEpGdzh/
編輯:這是一個與可能的重復項不同的問題,因為此問題不會產生任何錯誤,而且它是雙向綁定格式的更簡單和本地化的問題。
這是因為check_send
需要在文檔中編寫時是testChange
,而Angular則使用xxxChange
語法對該代碼進行xxxChange
糖。
<child-component [test]="check" (testChange)="check=$event">This child updates all</child-component>
@Output() testChange = new EventEmitter<number>();
this.testChange.emit(this.test);
固定的插頭: https ://plnkr.co/edit/zGupQPkS6MoV3xMQefxN ? p = info
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.