我对 Angular/Typescript 相当陌生。我有点一边学习一边发展。我正在尝试使用从 Json 文件加载的数据构建网格,但在显示数据时遇到一些问题。如果你们能指出我的错误,我会很高兴,因为我的代码编译没有错误,而我现在有点无助。
我将在下面提供我的代码。提前致谢。
my-grid-application.component.ts
@Component({
selector: 'app-my-grid-application',
templateUrl: './my-grid-application.component.html'
})
export class MyGridApplicationComponent {
private gridOptions: GridOptions;
things:Things[];
getThings(){
this.myGridApplicationService.getThings().subscribe( things =>
this.things = things)
}
constructor( private myGridApplicationService: MyGridApplicationService) {
this.gridOptions = <GridOptions>{};
var gridOptions = {
onGridReady: function() {
this.gridOptions.api.setRowData(this.things);
}
}
this.gridOptions.columnDefs = [
{
headerName: "ID",
field: "id",
width: 100
},
{
headerName: "Value",
field: "value",
cellRendererFramework: RedComponentComponent,
width: 100
},
];
}
}
Run Code Online (Sandbox Code Playgroud)
my-grid-application.service.ts
export class Things{
}
@Injectable()
export class MyGridApplicationService …Run Code Online (Sandbox Code Playgroud)