查询列表为空,如何访问嵌套的ng-content angular

时间:2018-02-24 17:36:47

标签: angular typescript

我有三个组件

1) item(html)

 <div>
    <ng-content></ng-content>
 </div>

2) list-container(html)

<ng-content></ng-content>

列表容器(TS)

  @ContentChildren(forwardRef(() => Item), { descendants: true }) Items: QueryList<Item>;
  ngAfterContentInit(): void {
    console.log(this.Items); // issue is here. query List is empty
// how to access items
      }

3)容器(html)

<container-list>
    <ng-content></ng-content>
</container-list>
app.html中的

<container>
    <item *ngFor="let item of items">{{item.name}}</item>
</container>

0 个答案:

没有答案