我正在使用PrimeNG DataTable组件,需要访问放置在列模板标签内的元素 .

如果使用* ngFor手动生成表(不需要模板),则一切正常但在切换到PrimeNG组件后,我的@ViewChildren列表始终为空 .

@Component({
  ...
  template: `

      <p-dataTable [value]="myList">
          <p-column header="Header">
              <template let-item="rowData" let-index="rowIndex" pTemplate type="body">
                <my-component #myComponent [item]="item"></my-component>
              </template>
          </p-column>       
      </p-dataTable>
  `,
})
export class MyOtherComponent {

    @ViewChildren('myComponent') myComponents: QueryList<MyComponent>;
}

我试图订阅QueryList更改,并在表行添加或删除后触发事件,但总是得到0长度'_results'数组(使用* ngFor数组与组件数正确同步) .

在DataTable的情况下

this.myComponents.changes.subscribe((changes) => console.log(changes));

总是回报:

QueryList {_dirty:false,_results:Array [0],_发送者:EventEmitter}

Is there any way to get it working?