网格网格单元渲染错误
我正在使用AG-GRID api在我的网站中的main.ts文件下填充一个表,我添加了以下代码
I am using the AG-GRID api to populate a table in my website under the main.ts file i have added the following code
import { bootstrap } from 'angular2/platform/browser';
import { AppComponent } from './app.component';
import { ROUTER_PROVIDERS } from 'angular2/router';
import { AgGridModule } from 'ag-grid-ng2/main';
bootstrap(AppComponent, [ROUTER_PROVIDERS],AgGridModule);
我的主要component.ts文件如下
my main component.ts file is as following
import { Component } from 'angular2/core';
import { GridOptions } from 'ag-grid/main';
@Component({
moduleId: module.id,
templateUrl:"app/grid.component.html";
})
export class gridComponent{
public gridOptions:GridOptions;
constructor() {
this.gridOptions = <GridOptions>{};
this.gridOptions.rowData = this.createRowData();
this.gridOptions.columnDefs = this.createColumnDefs();
}
private onCellValueChanged($event) {
this.gridOptions.api.refreshCells([$event.node],["cube"]);
}
private createColumnDefs() {
return [
{headerName: "Row 1", field: "row", width: 140}
];
}
public refreshRowData() {
let rowData = this.createRowData();
this.gridOptions.api.setRowData(rowData);
}
private createRowData() {
let rowData:any[] = [];
for (var i = 0; i < 15; i++) {
rowData.push({
row: "Name" + i
});
}
console.log(rowData);
return rowData;
}
}
我编译时遇到找不到模块的错误。
谁能帮忙
预先感谢
When i compile i get a error of module not found. Can anyone help Thanks in advance
您不应该在main.ts中声明它,在app.module.ts中,您需要以下内容:
You shouldn't declare it in main.ts, in app.module.ts you need something like the following:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { AgGridModule } from 'ag-grid-ng2/main';
@NgModule({
imports:[
BrowserModule,
AgGridModule
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
然后在 system.config.js
中,您需要告诉angular在哪里可以找到ag-grid文件:
Then in system.config.js
you need to tell angular where to find the ag-grid files:
System.config({
map: {
...
// ag libraries
'ag-grid-ng2' : 'node_modules/ag-grid-ng2',
'ag-grid' : 'node_modules/ag-grid',
},
packages: {
'ag-grid-ng2': {
defaultExtension: "js"
},
'ag-grid': {
defaultExtension: "js"
},
...other packages
}
}
有关更多信息,请访问angular2网站 https:/ /www.ag-grid.com/ag-grid-angular-systemjs
More information is available on the angular2 site https://www.ag-grid.com/ag-grid-angular-systemjs