javascript - Angular http 调用标头显示 200 响应,但响应数据显示 html 而不是 json 数据
问题描述
我正在使用 httpClient 对 api 进行 http 调用并在 ngfor 中显示项目。这似乎有效,因为我的列表中显示了三个项目,就像从我的 api 返回的三个项目一样。但是我似乎无法访问返回的 json 数据。当我在 chrome 的网络选项卡中查看网络调用时,我看到 200 成功,但响应是 html。我猜我需要在某处指定 json 数据类型,但我不确定。
这是我的服务中的 http 调用:
getProducts(): Observable<Product[]> {
return this.http.get<Product[]>(this.competitionUrl)
这是我尝试使用组件中的数据的方式:
productlist = this.productdataservice.getProducts()
在我的html中:
<ion-list *ngFor="let product of productlist | async; let i = index">
<button ion-item>
<ion-avatar item-start>
<img src="../../assets/icon/favicon.png">
</ion-avatar>
<h2>{{product.productName}}</h2>
</button>
</ion-list>
我的列表应该显示三个图标,因为我的 api 返回三个产品,但是当我从我的角度前端页面查看网络调用时,我没有看到 json 数据。
解决方案
推荐阅读
- python - 在 Python 中将多个项目复制到剪贴板
- amazon-web-services - npm 好慢,连 npm -v 都需要 30sec
- java - 我们可以使用 BufferedReader 读取文件并使用 BufferedOutputStream 将内容写入另一个文件吗?反之亦然
- python - 我有两个数据框 df1 和 df2,我需要使用 df2 中的键过滤掉 df1,使用 df2 中的开始日期和结束日期,我需要得到像 df3 这样的结果
- ios - 无法在使用 Agora iOS SDK 的模拟器上运行我的应用
- javascript - Javascript从多级数组中排序数据?
- sql - Oracle 12c Json 拆分
- javascript - 在默认函数中调用另一个函数
- powershell - 从管理门户上显示的所有 Office 365 组中删除 CVS 文件中的禁用用户
- android - 带有 RecyclerView 的运动布局,在 recyclerview 的末尾滚动