设置样品表时遇到问题。“无法为 rowModelType 客户端找到匹配的行模型”

Ser*_*nov 20 ag-grid-angular

我一直在阅读有关新项目的 ag-grid 的“入门”教程。已完成所有步骤,但出现错误提示

ag-Grid: could not find matching row model for rowModelType clientSide
ag-Grid: Row Model "Client Side" not found. Please ensure the ClientSideRowModelModule is loaded using: import '@ag-grid-community/client-side-row-model';
Run Code Online (Sandbox Code Playgroud)

将我的所有代码与教程中提供的示例和一些 plunker 示例进行了比较,没有发现任何差异。尝试将 ClientSideRowModelModule 导入 app.module 但接口与 angular 请求的内容不匹配,因此它不起作用。我没有想法,也找不到有关如何解决它的任何信息。

app.module.ts:

    ... imports: [
    BrowserModule,
    AppRoutingModule,
    AgGridModule.withComponents([])
  ],...
Run Code Online (Sandbox Code Playgroud)

app.cpmcomponent.html:

<ag-grid-angular 
style="width: 500px; height: 500px;" 
class="ag-theme-balham"
[rowData]="rowData" 
[columnDefs]="columnDefs"
 >
</ag-grid-angular>
Run Code Online (Sandbox Code Playgroud)

app.component.ts:

    ...columnDefs = [
      {headerName: 'Make', field: 'make' },
      {headerName: 'Model', field: 'model' },
      {headerName: 'Price', field: 'price'}
  ];

  rowData = [
      { make: 'Toyota', model: 'Celica', price: 35000 },
      { make: 'Ford', model: 'Mondeo', price: 32000 },
      { make: 'Porsche', model: 'Boxter', price: 72000 }
  ];...
Run Code Online (Sandbox Code Playgroud)

我正在使用 Angular:8.2.10,Angular CLI:8.2.2,npm:6.9.0

小智 22

在你的 app.component.ts 中,你首先需要导入 ClientSideRowModelModule

import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';
Run Code Online (Sandbox Code Playgroud)

然后在 AppComponent 类中,您需要创建一个模块数组变量,如下所示:

modules: Module[] = [ClientSideRowModelModule];
Run Code Online (Sandbox Code Playgroud)

最后,在您的 app.component.html 中,您需要将其绑定到 ag-grid-angular 组件

<ag-grid-angular 
style="width: 500px; height: 500px;" 
class="ag-theme-balham"
[rowData]="rowData" 
[columnDefs]="columnDefs"
[modules]="modules"
 >
</ag-grid-angular>
Run Code Online (Sandbox Code Playgroud)

有关更多资源,请查看AgGrid 的文档,这是安装 AgGrid 模块的第 3 步。

  • 非常感谢!我应该花更多时间阅读文档 (2认同)