无法读取角度6中未定义的属性'aDataSort'

时间:2019-03-22 11:20:58

标签: angular angular6 angular-datatables

我正在尝试通过从某个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>

0 个答案:

没有答案