angular5 - 角度 ag 网格不适用于角度 5
问题描述
我想ag-grid
在我的 Angular 5 应用程序中使用,但我无法使用,因为它在我的控制台中引发异常。
我的组件代码:
columnDefs = [
{headerName: "First Name", field: "first_name", width: 100, editable: true},
{headerName: "Last Name", field: "last_name", width: 100, editable: true},
{
headerName: "Gender",
field: "gender",
width: 90,
cellEditor: 'mySimpleCellEditor'
},
{
headerName: "Age",
field: "age",
width: 70,
cellEditor: 'mySimpleCellEditor'
},
{
headerName: "Mood",
field: "mood",
width: 70,
cellEditor: 'mySimpleCellEditor'
},
{
headerName: "Country",
field: "country",
width: 100,
cellEditor: 'mySimpleCellEditor'
},
{
headerName: "Address",
field: "address",
width: 502,
cellEditor: 'mySimpleCellEditor'
}
];
rowData = [
{
first_name: 'Bob', last_name: 'Harrison', gender: 'Male',
address: '1197 Thunder Wagon Common, Cataract, RI, 02987-1016, US, (401)
747-0763',
mood: "Happy", country: 'Ireland'
},
];
我的html代码:
<div>
<ag-grid-angular #aggrid style="width: 100%; height: 350px;"
class="ag-theme-balham"
[columndefs]="columnDefs"
[showtoolpanel]="true"
[rowdata]="rowData"
enablecolresize
enablesorting
enablefilter
rowheight="22"
rowselection="multiple">
</ag-grid-angular>
</div>
我的app.module.ts
代码:
import { AgGridModule } from "ag-grid-angular/main";
imports: [
AgGridModule.withComponents([])
],
我的控制台中仍然出现以下错误,并且无法运行我的应用程序。
(anonymous) @ bootstrap.min.js:6
compiler.js:215 Uncaught Error: Template parse errors:
Can't bind to 'columndefs' since it isn't a known property of 'ag-grid-
angular'.
1. If 'ag-grid-angular' is an Angular component and it has 'columndefs'
input, then verify that it is part of this module.
2. If 'ag-grid-angular' is a Web Component then add
'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to
suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas'
of this component. ("id-angular #aggrid style="width: 100%; height: 350px;"
class="ag-theme-balham"
[ERROR ->][columndefs]="columnDefs"
[showtoolpanel]="true"
[rowdata]="): ng:///AppModule/GridtestComponent.html@3:21
Can't bind to 'showtoolpanel' since it isn't a known property of 'ag-
grid-angular'.
1. If 'ag-grid-angular' is an Angular component and it has 'showtoolpanel'
input, then verify that it is part of this module.
我几乎尝试了所有方法,但仍然无法解决此问题。
解决方案
你需要在 app.module 中导入这个:
import { NgModule, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
@NgModule({
schemas: [
CUSTOM_ELEMENTS_SCHEMA,
NO_ERRORS_SCHEMA
],
...
推荐阅读
- c# - .NetCore 将带有数组的 JSON 对象绑定到字典
- sql - 如何从最大日期小于表 A 中的日期的表 B 中获取值
- c++ - 如何初始化对象中的静态指针数组
- c# - Active Directory / LDPA 未使用长用户名进行身份验证
- go - 如何使用 client-go 在 Pod 的容器中执行多个命令?
- python - 使用循环写入目录中的每个文件
- microsoft-teams - 我可以用一个命令呼叫团队中的所有成员吗
- api - 用于确定照片是从照片还是真人中单击的 Api
- android - 应用程序关闭后 RoomDatabase 对象上的 Android NullPointerException
- javascript - 为什么此代码片段中的圆圈落后于实际的鼠标光标?