【发布时间】:2020-08-26 11:29:20
【问题描述】:
我有一个基于 Angular 的应用程序正在向服务器发出 RESTful 请求,其响应是 JSON 流,表示以下类型的对象列表:
export interface Personal {
theAddress: string;
theCity: string;
theState: String;
theCountry: string;
emailAddress: string;
}
我的组件中的代码使用 HttpClient GET 请求来获取要放入 Observable 的数据:
people$: Observable<Personal[]>;
...
ngOnInit() {
this.people$ = this.http
.get<Personal[]>("/people/get")
.map(data => _.values(data))
.do(console.log);
}
由于各种原因,我想提取 Observable 的内容并将它们放入人员对象数组中。在阅读了 Internet 上的各种文档后,我知道要提取收到的数据,我需要以某种方式在 Observable 上使用订阅方法。不幸的是,我不清楚具体该怎么做。
有人可以帮忙吗?如何将 Observable 接收到的对象提取到数组中?
【问题讨论】:
标签: angular typescript rest