这可能更像是一个有角度的问题,但我正在尝试在加载数据(并动态显示/隐藏列)后调整清晰度数据网格,但我不断收到错误
未捕获的TypeError:无法读取未定义的属性'resize'
component.html
<clr-datagrid #contactsGrid>
[...]
</clr-datagrid>
component.ts
import { Component, OnInit, ViewChild } from '@angular/core';
import { Datagrid } from "clarity-angular";
export class GridComponent implements OnInit {
@ViewChild('contactsGrid') datagrid: Datagrid;
//@ViewChild('Datagrid') datagrid: Datagrid; //This doesn't work either
constructor( ) { }
ngOnInit() {
[...]
this.datagrid.resize(); //this.datagrid is undefined
}
}
1 回答
看来你上面的示例代码是正确的,也许会有更多的事情发生?您是否有更完整的示例可以分享实际问题?
您可以在此处看到获取数据网格参考的演示 . https://stackblitz.com/edit/clarity-datagrid-brfwx9?file=app/launches/launches.component.ts
该模板具有:
然后控制器有:
如果您只有一个Datagrid,则无需在HTML中添加钩子
看起来你的代码传递了
'Datagrid'
(一个字符串)而不是Datagrid
(对构造函数的引用)