【问题标题】:Can't bind to 'gridOptions' since it isn't a known property of 'ag-grid-angular' (Angular4)无法绑定到“gridOptions”,因为它不是“ag-grid-angular”(Angular4)的已知属性
【发布时间】:2018-11-14 01:38:09
【问题描述】:

我在 HTML 中有这段代码:

<ag-grid-angular [gridOptions]="gridOptions"></ag-grid-angular>

组件中的代码:

import {GridOptions} from 'ag-grid'; 
...

export class SampleComponent{
   gridOptions: GridOptions;
}
...

app.module.ts:

import {NgModule} from "@angular/core";
import {AgGridModule} from "ag-grid-angular/main";
import {AppComponent} from "./app.component";
...

@NgModule({
    declarations: [...],
    imports: [
        ...
        AgGridModule.withComponents([])
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule {
}

我得到的错误的根源是什么? 这是完整的错误:

错误:未捕获(承诺中):错误:模板解析错误:无法绑定 到“gridOptions”,因为它不是“ag-grid-angular”的已知属性。

  1. 如果“ag-grid-angular”是一个 Angular 组件并且它具有“gridOptions”输入,则验证它是该模块的一部分。
  2. 如果“ag-grid-angular”是一个 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”中 禁止显示此消息。

【问题讨论】:

  • 你能发布你的 app.module.ts
  • @Sanoj_V 解决方案是该问题不能解决我的问题。我已经在导入中有AgGridModule.withComponents([])
  • @Sajeetharan 是的,我已经添加了 app.module.ts
  • 我不知道这是否会有所帮助,但在我使用ag-grid 的班级中,我有以下导入:import { AgGridNg2 } from 'ag-grid-angular';(我没有AgGridModule 的导入)。

标签: angular typescript ag-grid


【解决方案1】:

尝试如下初始化gridOptions看看

constructor() {
    this.gridOptions = <GridOptions>{};
    this.columnDefinitions = [

    ];

    this.gridOptions = {
      columnDefs: this.columnDefinitions,
      enableFilter: true,
      enableSorting: true,
      pagination: true
    };

    this.rowSelection = 'single';
  }

编辑

你的实际问题在这里,改变

来自

<ag-grid-angular [gridOptions]="gridOptions"></ag-grig-angular>

<ag-grid-angular [gridOptions]="gridOptions"></ag-grid-angular>

【讨论】:

  • 感谢您的建议,但不幸的是它没有工作:(
  • 哦,这很奇怪!我可以看看你的完整代码吗
  • 我可以知道您使用的是什么版本吗?如果它与版本有关。
  • 不是版本问题,是拼写问题,请查看编辑后的答案
  • 感谢您发现这一点。我打错了。所以,我上次尝试将[gridOptions]... 全部删除,但出现错误:ag-grid-angular' is not a known element
【解决方案2】:

您也可以在您的 cae 中创建没有 gridOptions 的网格。请在下面找到完整的代码:-

<ag-grid-angular style="width: 500px;height: 200px;" class="ag-theme-balham" [animateRows]="true" [columnDefs]="columnDefs" [enableSorting]="true" [enableFilter]="true" (gridReady)="OnGridReady($event)">

【讨论】:

    猜你喜欢
    • 2017-10-29
    • 2022-01-27
    • 2020-09-24
    • 2021-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-04
    相关资源
    最近更新 更多