【问题标题】:Can't bind to 'columnDefs' since it isn't a known property of 'ag-grid-angular'无法绑定到“columnDefs”,因为它不是“ag-grid-angular”的已知属性
【发布时间】:2021-06-25 17:37:21
【问题描述】:

我收到关于Can't bind to 'columnDefs' since it isn't a known property of 'ag-grid-angular' 的错误消息。我已经阅读了一些针对类似问题的建议,但没有一个建议的答案解决了我的问题。我的 HTML 是这样的:

<ag-grid-angular class="my-class-here"
    ...
    [columnDefs]="gridColumnDefs"
    ...
</ag-grid-angular>

我的 component.ts 文件有这些:

import { ColDef } from 'ag-grid-community';

public gridColumnDefs = myGridColDefs;

其中myGridColDefs 是代表我的列定义的变量。在我的 module.ts 文件中,我已经像这样导入了 ag-grid:

import { AgGridModule } from 'ag-grid-angular';

@NgModule({
    imports: [
        AgGridModule.withComponents([]),
        ...
    ]
})

据我所知,我做的一切都是正确的。什么可能导致此错误消息?仅供参考,我还会收到其他错误消息,因为它无法识别这样的 ag-grid 属性:

Can't bind to 'rowData' since it isn't a known property of 'ag-grid-angular'.
        1. If 'ag-grid-angular' is an Angular component and it has 'rowData' input, then verify that it is part of this module.

ag-grid documentation 显示这样的 HTML

<ag-grid-angular
    [columnDefs]="columnDefs"
    /* other grid options ... */>
</ag-grid-angular>

所以我不明白为什么会遇到这个问题。

【问题讨论】:

  • 你使用的是什么 ag-grid 版本,你使用的是什么角度?您确定要将 AgGridModule 导入您尝试使用该组件的同一模块中吗?

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


【解决方案1】:

您可以尝试删除 node_modules 和 package-lock.json,然后在您的 package.json 所在的文件夹中运行 npm install

【讨论】:

    【解决方案2】:

    问题出在我的 spec.ts 文件中。我需要像这样添加导入和模式:

    TestBed.configureTestingModule({
            imports: [
                RouterTestingModule,
                MocksModule,
                AnotherModule
            ],
            declarations: [ nameOfMyComponent ],
            schemas: [
                CUSTOM_ELEMENTS_SCHEMA,
            ]
        })
    

    我在其他一些类似的问题中看到并回答了一些关于 schemas: [ CUSTOM_SLEMENTS_SCHEMA, ] 的事情,建议在 module.ts 文件中放置这样的一行 - 我知道这不是我的问题,因为我能够运行和调试& 显示数据。在我的情况下,我需要在 spec.ts 文件中使用上述代码,因为我正在运行测试命令。

    【讨论】:

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