我正在尝试通过从某个API获取数据来绘制数据表。但是我收到上面的错误。当我在表中使用* ngFor循环时,我能够获得数据表。但是我不希望使用* ngFor来使用这种格式。这是什么问题,以及如何解决此错误?
dashboard.ts
export class DashboardComponent implements OnInit {
dtOptions: DataTables.Settings = {};
dtTrigger: any = new Subject();
sampleData: any;
constructor(private dashboard: DashboardService) {}
ngOnInit() {
this.getJsonData();
}
dataTable() {
console.log(this.sampleData);
let self = this;
this.dtOptions = {
pagingType: "full_numbers",
pageLength: 4,
data: this.sampleData,
columns: [
{
title: "ID",
data: "id"
},
{
title: "Name",
data: "name"
},
{
title: "UserName",
data: "username"
},
{
title: "Email",
data: "email"
},
{
title: "Website",
data: "website"
}
]
};
}
getJsonData() {
this.dashboard.fetchSampleJson().subscribe(res => {
console.log(res);
this.sampleData = res;
this.dtTrigger.next();
this.dataTable();
});
}
ngOnDestroy(): void {
this.dtTrigger.unsubscribe();
}
}
dashboard.html
<table
datatable
[dtOptions]="dtOptions"
[dtTrigger]="dtTrigger"
class="row-border hover table"
>
<table>