我使用Ag-grid以成角度的形式显示行数据,使用存储在我的assests文件夹中的json数据,并使用Httpclient读取数据。但是该数据未加载,错误为as,
错误TypeError:无法读取null的属性'dispose'
但是当我尝试在控制台中打印json数据时,其显示正确,
。ts文件为,
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-staticdata',
templateUrl: './staticdata.component.html',
styleUrls: ['./staticdata.component.css']
})
export class StaticdataComponent implements OnInit {
constructor(private http:HttpClient) { }
ngOnInit(): void {
this.http.get("assets/user.json").subscribe(data =>{
console.log(data);
this.rowData = data;
})
}
columnDefs = [
{field: 'name',header:"Name"},
{field: 'value',header:"Value" }
];
rowData:any=[];
}
模板文件是,
<ag-grid-angular
style="width: 500px; height: 200px;"
class="ag-theme-alpine"
[rowData]="rowData | async"
[columnDefs]="columnDefs">
</ag-grid-angular>
<br>
<button mat-raised-button color="primary">Add</button>
<button mat-raised-button color="primary">Delete</button>
<button mat-raised-button color="primary">Save</button>
json文件是,
[
{
"name":"",
"value":"Only laptop user"
},
{
"name":"",
"value":"Only Dektop user"
},
{
"name":"",
"value":"HVD with desktop"
},
{
"name":"",
"value":"HVD with laptop"
},
{
"name":"",
"value":"Dual assests laptop and desktop"
}
]
是的,我希望coloumn这个名字现在应该为空。预先感谢。
您将rowData指定为异步: