【发布时间】:2020-06-07 12:10:53
【问题描述】:
我正在尝试为具有types === "locality" 的项目打印long_name。我正在使用 Angular 和 httpClient,这使得可观察到。我迷失在 rxjs 和 js 的复杂性中。
有人可以帮忙吗?
服务:
getGoogleGeo2(postalCode: string) {
return this.http
.get(`https://maps.googleapis.com/maps/api/geocode/json?address=${postalCode}ES&key=${api}`)
.pipe(map(<T>(item) => item.results[0].address_components));
}
组件:
this.geoService.getGoogleGeo2(postalCode).subscribe((item) => console.log(item));
我在我的 console.log 中得到了这个:
[
{ long_name: "08820", short_name: "08820", types: ["postal_code"] },
{ long_name: "El Prat de Llobregat", short_name: "El Prat de Llobregat", types: ["locality", "political"] },
];
在我的组件中,我需要保存值 El Prat de Llobegrat,然后在 html 中使用。
【问题讨论】:
标签: angular rxjs httpclient subscribe rxjs-observables