【问题标题】:How to bind with component recursion in angular如何以角度绑定组件递归
【发布时间】:2018-04-23 12:27:09
【问题描述】:

我得到了这个简单的代码:

@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!

如何解决?

【问题讨论】:

    标签: javascript angular typescript data-binding angular6


    【解决方案1】:

    找到解决方案:

    <app-tree [(content)]="content.childs"
       *ngFor="let contentChild of content.childs"></app-tree>
    

    你不能有两种方式绑定,只有 [reference] 和 *ngFor 但是你可以直接绑定对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-26
      • 2020-06-06
      • 1970-01-01
      • 2018-04-05
      • 2012-03-30
      • 1970-01-01
      • 2020-01-03
      • 2019-03-09
      相关资源
      最近更新 更多