【发布时间】:2020-04-30 09:25:44
【问题描述】:
我在 html 页面中有多个 ag-grid,我想在组件中获取 ag-grid 的特定行值。
html
<ag-grid-angular #agGrid1 style="width: 1250px; margin-left: 5px ; height:120px;background-color: #CFD8DC;"
class="ag-theme-balham" [rowData]="rowsData1" [columnDefs]="cols" rowSelection="multiple"
[enableCellChangeFlash]="true">
</ag-grid-angular>
<ag-grid-angular #agGrid2 style="width: 1250px; margin-left: 5px ; height:120px;background-color: #CFD8DC;"
class="ag-theme-balham" [rowData]="rowsData2" [columnDefs]="cols2" rowSelection="multiple"
[enableCellChangeFlash]="true">
</ag-grid-angular>
组件.ts
@ViewChild('agGrid1', { static: true }) agGrid: AgGridAngular;
@ViewChild('agGrid2', { static: true }) agGrid2: AgGridAngular;
getRowsData() {
this.selectedRows1 = this.agGrid.api.getSelectedRows();
this.selectedRows2 = this.agGrid2.api.getSelectedRows();
console.log( this.selectedRows1, this.selectedRows2)
}
在这里我试图获取两个 ag-grid 行的值,但我得到:
ERROR TypeError: Cannot read property 'api' of undefined error.
【问题讨论】:
-
嗨 @Zameer,请查看 StackOverflow 的 How to ask 指南。在当前状态下-您的问题将被关闭。请插入您尝试过的代码,预期结果是什么以及实际发生了什么。如果有错误日志 - 也包括它。也许添加一个可复制的链接到stackblitz.com ?
-
不,它没有解决问题