【问题标题】:Unable to fetch data from asp.net core api into angular 6无法从 asp.net core api 获取数据到角度 6
【发布时间】: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>

Blank Grid Image

【问题讨论】:

  • 我认为问题在于异步调用,因为页面正在形成,返回 6 条记录,每个页面可以有 5 条记录,因此创建了 2 个页面
  • 你的控制台有错误吗?
  • 控制台没有错误,请帮我解决这个问题
  • 您确定数据上的属性以大写字母开头吗?你能去{{item | json}} 在你的第一个单元格中检查?
  • 你能发布你的组件代码吗?

标签: angular datatables angular6


【解决方案1】:

从您可以实际看到数据可用的图片(有行)我强烈怀疑您在应用程序的 ASP 端使用CamelCasePropertyNamesContractResolver。这意味着即使 C# 中的属性名称以大写字母开头,返回的 JSON 也会使用驼峰式大小写(以小写字母开头)

【讨论】:

    猜你喜欢
    • 2018-04-23
    • 1970-01-01
    • 2021-11-29
    • 2017-09-26
    • 2019-03-04
    • 2019-05-15
    • 2017-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多