[英]How to bind with component recursion in angular
我得到了以下簡單代碼:
@Component({
selector: 'app-tree',
template: `<div>{{content.name}}</div>
<app-tree [(content)]="contentChild"
*ngFor="let contentChild of content.childs"></app-tree>`
})
export class TreeComponent {
@Input() content: Content;
}
但是[(content)]="contentChild"
引發了以下錯誤:
ERROR Error: Uncaught (in promise): Error: Cannot assign to a reference or variable!
如何解決呢?
找到了解決方案:
<app-tree [(content)]="content.childs"
*ngFor="let contentChild of content.childs"></app-tree>
您不能有兩種方式綁定,只有帶有* ngFor的[reference]綁定,但是您可以直接綁定對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.