【发布时间】:2019-03-10 00:15:27
【问题描述】:
后端的net core api项目,使用angular 6,使用数据表插件显示网格,数据从api传递但没有显示在显示空白网格的网格中
以下是服务文件代码
export class DoctorsServiceService {
formData : DoctorVM;
readonly rootUrl = "https://localhost:44317/api/";
list: DoctorVM[];
constructor(private http:HttpClient) { }
getDoctors(){
this.http.get(this.rootUrl+"Doctors").toPromise().then(res => this.list =
res as DoctorVM[]);
}
}
以下是html文件代码
<table class="table table-striped" [mfData]="service.list" #mf="mfDataTable"
[mfRowsOnPage]="5">
<thead>
<tr>
<th>
<mfDefaultSorter by="name">Name</mfDefaultSorter>
</th>
<th>
<mfDefaultSorter by="email">Gender</mfDefaultSorter>
</th>
<th>
<mfDefaultSorter by="age">Specialities</mfDefaultSorter>
</th>
<th style="width: 20%">
<mfDefaultSorter by="city">AverageRating</mfDefaultSorter>
</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of mf.data">
<td>{{item.Name}}</td>
<td>{{item.Gender}}</td>
<td>{{item.Specialities}}</td>
<td>{{item.AverageRating}}</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">
<mfBootstrapPaginator></mfBootstrapPaginator>
</td>
</tr>
</tfoot>
【问题讨论】:
-
我认为问题在于异步调用,因为页面正在形成,返回 6 条记录,每个页面可以有 5 条记录,因此创建了 2 个页面
-
你的控制台有错误吗?
-
控制台没有错误,请帮我解决这个问题
-
您确定数据上的属性以大写字母开头吗?你能去{{item | json}} 在你的第一个单元格中检查?
-
你能发布你的组件代码吗?
标签: angular datatables angular6