繁体   English   中英

如何绑定组件递归角度

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM