我收到了一条关于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网格:
import { AgGridModule } from 'ag-grid-angular';
@NgModule({
imports: [
AgGridModule.withComponents([]),
...
]
})据我所知,我把一切都做对了。是什么导致了这个错误消息?FYI我还得到了额外的错误消息,当它没有识别这样的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-网格文档显示的HTML如下
<ag-grid-angular
[columnDefs]="columnDefs"
/* other grid options ... */>
</ag-grid-angular>所以我不明白我为什么要经历这个问题。
发布于 2021-03-29 19:56:43
这个问题最终出现在我的spec.ts文件中。我需要添加这样的导入和模式:
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
MocksModule,
AnotherModule
],
declarations: [ nameOfMyComponent ],
schemas: [
CUSTOM_ELEMENTS_SCHEMA,
]
})在其他类似的问题和答案中,我看到了一些关于schemas: [ CUSTOM_SLEMENTS_SCHEMA, ]的东西,建议在module.ts文件中添加这样的一行--我知道这不是我的问题,因为我能够运行&调试和显示数据。在我的例子中,我需要spec.ts文件中的上述代码,因为我正在运行一个测试命令。
发布于 2021-03-29 18:57:13
您可以尝试删除node_modules和Packy-lock.json,然后在package.json所在的文件夹中运行npm install。
https://stackoverflow.com/questions/66858477
复制相似问题