我收到一条关于 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>
所以我不明白为什么我会遇到这个问题。
答案 0 :(得分:0)
您可以尝试删除 node_modules 和 package-lock.json,然后在 package.json 所在的文件夹中运行 npm install
。
答案 1 :(得分:0)
问题出在我的 spec.ts 文件中。我需要添加这样的导入和模式:
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
MocksModule,
AnotherModule
],
declarations: [ nameOfMyComponent ],
schemas: [
CUSTOM_ELEMENTS_SCHEMA,
]
})
我在其他一些类似的问题中看到并回答了一些关于 schemas: [ CUSTOM_SLEMENTS_SCHEMA, ]
的事情,建议在 module.ts 文件中放置这样的一行 - 我知道这不是我的问题,因为我能够运行& 调试 & 显示数据。就我而言,我在 spec.ts 文件中需要上述代码,因为我正在运行测试命令。