【发布时间】:2018-09-07 16:52:03
【问题描述】:
我正在使用 ag-grid 许可证版本,并希望使用服务将记录集带入网格。我正在使用 Ag-Grid gridoption 属性并初始化 rowdata 在 component.ts 类的构造函数中。但是数据没有渲染。也没有错误。请看看我的 component.ts 类。
请注意:web api 正确返回 json 数据,并且在没有 Ag-Grid 的情况下成功测试了 Angular 中的服务
import {Component, OnInit} from "@angular/core";
import {GridOptions} from "ag-grid";
import {RedComponentComponent} from "../red-component/red-component.component";
import { person } from "../Shared/models/person.model";
import {personservice} from '../service/person.service';
@Component({
selector: 'app-my-grid-application',
templateUrl: './my-grid-application.component.html'
})
export class MyGridApplicationComponent implements OnInit{
private gridOptions: GridOptions;
private persons: person[];
constructor(private personservice: personservice) {
this.gridOptions = <GridOptions>{};
this.gridOptions.columnDefs = [
{
headerName: "ID",
field: "PersonId",
width: 100
},
{
headerName: "Name",
field: "PersonNm",
cellRendererFramework: RedComponentComponent,
width: 100
},
{
headerName: "Email",
field: "PersonEmail",
cellRendererFramework: RedComponentComponent,
width: 100
}
];
this.gridOptions.rowData = this.persons
}
ngOnInit() {
this.personservice.findAll().subscribe(
persons => {
this.persons = persons
},
error => {
console.log(error);
}
)
}
}
【问题讨论】:
-
能分享一下.html页面写的代码