ag-grid角度获取元素参考

时间:2019-04-22 17:14:33

标签: angular ag-grid ag-grid-angular

如何在Angular的grid元素上获取DOM引用?似乎没有直接的方法。我尝试过:

标记:

<ag-grid-angular #logGrid></ag-grid-angular>

ts:

@ViewChild('logGrid') logGrid: AgGridNg2;

AgGridNg2没有公开的nativeElement或ElementRef属性。

我也尝试过:

@ViewChild('logGrid') logGrid: ElementRef;

它没有nativeElement属性,因为它的类型是AgGridNg2而不是ElementRef。

我需要DOM引用,因为其中的内容ag-grid doesn't expose scrollHeight

2 个答案:

答案 0 :(得分:1)

通过将装饰器的ViewChildread属性设置为ElementRef,可以获取对组件的host元素的引用:

@ViewChild('logGrid', { read: ElementRef }) logGridElementRef: ElementRef;

答案 1 :(得分:0)

看来您必须使用本机js DOM查询:

标记

<ag-grid-angular id="logGrid"></ag-grid-angular>

ts:

logGrid: HTMLElement;

ngAfterViewInit() {
  this.logGrid = document.getElementById('logGrid');

  const logBody = this.logGrid.querySelector('.ag-body-viewport');
      console.log('log body', logBody.scrollHeight);
}