无法绑定到 'columnDefs',因为它不是 'ag-grid-angular' 的已知 属性

Can't bind to 'columnDefs' since it isn't a known property of 'ag-grid-angular'

我收到关于 Can't bind to 'columnDefs' since it isn't a known property of 'ag-grid-angular' 的错误消息。我已经阅读了一些针对类似问题的建议,但 none 的建议答案解决了我的问题。我的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>

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

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

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

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

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