Angular Ng5用于不在datatables.net上工作
下面是我想使用ngFor在数据表中显示数据时出错的屏幕截图:Angular Ng5用于不在datatables.net上工作,datatables,angular5,Datatables,Angular5,下面是我想使用ngFor在数据表中显示数据时出错的屏幕截图: 您可以通过{{company.object}}尝试绑定这些数据经过一段时间的搜索,我发现了一些可以帮助您解决角度问题的步骤 首先,您需要绑定数据 <table id="datatables"> <thead> (...) </thead> <tfoot> (...) </tfoot> <tbody
您可以通过{{company.object}}尝试绑定这些数据经过一段时间的搜索,我发现了一些可以帮助您解决角度问题的步骤 首先,您需要绑定数据
<table id="datatables">
<thead>
(...)
</thead>
<tfoot>
(...)
</tfoot>
<tbody>
<tr *ngFor="let company of companies">
<td>company.id</td>
<td>company.systemArchitect</td>
<td>company.place</td>
<td>company.number</td>
<td>company.date</td>
<td>company.value</td>
<td>company.country</td>
</tr>
<tbody>
</table>
ref:您的数据源未正确绑定,请检查并实现ChangeDetectorRef保存了我的一天!
companies: Company[];
constructor(private companyService: CompanyService) {
this.companyService.getCompanies()
.subscribe(
(company: Company[]) => this.companies = company,
err => console.error(err),
() => console.log('done get company')
);
}
<table id="datatables">
<thead>
(...)
</thead>
<tfoot>
(...)
</tfoot>
<tbody>
<tr *ngFor="let company of companies">
<td>company.id</td>
<td>company.systemArchitect</td>
<td>company.place</td>
<td>company.number</td>
<td>company.date</td>
<td>company.value</td>
<td>company.country</td>
</tr>
<tbody>
</table>
companies: Company[];
constructor(private companyService: CompanyService, private chRef: ChangeDetectorRef) {}
ngOnInit(){
this.companyService.getCompanies()
.subscribe((company: Company[]) => {
this.companies = company;
// You'll have to wait that changeDetection occurs and projects data into
// the HTML template, you can ask Angular to that for you ;-)
this.chRef.detectChanges();
// Now you can use jQuery DataTables :
const table: any = $('datatables');
this.dataTable = table.DataTable();
});
}