angular - 尝试在 Angular 6 中使用对象 Object 作为数组
问题描述
这是我的问题的一些背景:
我正在用 Angular 6 编写一个应用程序,它应该从我的 localhost:5000 端口读取数据以获取 JSON 数据并将其显示在 Angular 应用程序中。角度应用程序完美地从我的本地主机获取数据,除非收集数据时,整个数据是一个“对象 Object”,我不知道如何迭代这种类型或可视化收集的数据。我知道数据被正确收集的原因是发布数据的服务器收到了 200 条成功消息。
这是我的角度应用程序正在接收的数据:
{"index":1,"Company":"Google","Hire Date":"1\/4\/16","Title":"Director"
,"Location":"Bay Area, CA","Degree":"Bachelors","Year entered
work force":1994.0,"Offer; Base":"$225,000.00
","Bonus":null,"Latitude":37,"Longitude":-122}
这是我在 Angular 中拟合数据的数据模型:
export interface Exam {
ID: number;
Company: string;
HireDate: string;
Title: string;
Location: string;
Degree: string;
yearEnteredWorkForce: string;
OfferCostNumber: string;
bonus: string;
latitude: number;
longitude: number;
}
这是作为“object Object”返回的变量
this.examsList = this.examsApi.getExams()
解决方案
import { Observable, Subscription } from 'rxjs/Rx';
/* 这应该添加到文件的顶部 */
this.examsApi.getExams().subscribe(res => {this.examsList = res)
/* Write code to do operation on your response object.*/
});
您将不得不使用 subscribe 方法,您将获得响应对象而不仅仅是[object, Object]。
推荐阅读
- javascript - Cloud Functions 和 Firestore:使用 Promise.all() 跟踪多个文档修改
- javascript - 重置多选下拉菜单反应
- python - 线路安排问题。(有人可以提出一个更省时的解决方案吗?)
- android - 尝试将推送通知集成到 Flutter 应用程序时未找到 ID 为“com.google.gms:google-services”的插件
- math - 尝试解决旋转
- python - RuntimeWarning:从未等待协程“FUNCTION”
- apache-ranger - Apache ranger 2.1.0 - 安装失败
- reactjs - 我应该为投资组合网站使用后端吗?
- angular - 在这种情况下,如何正确地将值从二级子组件传递给父组件?
- javascript - 应用程序前端的 Heroku 应用程序崩溃 h10 错误