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