c# - Angular7 - 从 API 调用中获取响应

标签 c# angular typescript asp.net-core asp.net-core-mvc

我是 Angular 7 的新手,正在尝试了解 Http Client 的工作原理。来自 Angular 应用程序的 API 调用已完成,但我得到如下响应

enter image description here

我的 service.ts 如下所示

export class ReportingFilterService {
 shipmentByProjectResult: any[];

  constructor(service: DataService) {
  }
  getShipmentByPrj(): ShipmentByProject[] {
    return this.shipmentByProjectResult;
   }
 }

其中 ShipmentByProject 是一个模型类

export class ShipmentByProject {
Id: string;
project_number: string;
related_project_number: string;
Reporting_Project: string;  
customer_shipto_name: string;
sales_order_TJL_ship_date: Date |string|null;
deliverydate: Date |string|null;
delivery_mode : string;
customer_purchase_order: string;
total_qty: number|null;
}

和组件

export class ReportingFilterComponent implements OnInit {
  ShipmentList: ShipmentByProject[];
  entityUrl = 'ShipmentDetail/GetByReportingProject?repPrj=000634';

  constructor(service: DataService) {
   service.get<ShipmentByProject[]>(this.entityUrl).subscribe(x => 
  {this.ShipmentList = x });
   }
 ngOnInit() {  }}

我只是调用 html 中的响应,如 Reporting filter works! {{ShipmentList}}。我不确定我在这里错过了什么。感谢任何帮助我正在学习 Angular 新手

最佳答案

因为你的数据是数组格式所以你应该像这样遍历你的数据

  <li *ngFor="let shipment of ShipmentList">
      {{ shipment.customer_shipto_name }}
  </li>

关于c# - Angular7 - 从 API 调用中获取响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57518765/

相关文章:

c# - LINQ 查找 2D 交错数组最小值,返回索引

c# - 在存储过程中使用日期时间作为参数更新表时出错

c# - 使用 C# 在 mongoDB 中存储具有多态值的字典

c# - 在 App.xaml 中添加不同的 BottomAppBars

javascript - 如何在 angular2 中使用 ngx-translate 获取当前语言

javascript - Angular 方法装饰器如何工作?

Angular Material2 日期选择器 - 动态格式化

typescript - 是否可以在 Typescript 的条件类型结果字段中使用通用参数值?

javascript - TypeScript 中的接口(interface)和类

javascript - 在某些属性中按部分搜索数组部分