【发布时间】:2021-08-28 02:05:38
【问题描述】:
我从 nodejs 后端获取位置作为对象数组。我已经在前端以角度订阅了它,它正在返回对象数组。如何获取每个对象的 name 属性?我正在尝试使用角度自动完成功能进行自动过滤。
组件文件
getLocations(){
this.locationService.getLocations().subscribe( (res )=> {
console.log(res);
})
}
服务文件
getLocations(): Observable<LocationTypes> {
const makeReqURL = `${this.apiURL}/`;
const getLocations = this.http.get<LocationTypes>(makeReqURL, { })
return getLocations;
}
来自前端响应的控制台日志图像。
添加 PIPE 后出错
提前谢谢你。
未定义的屏幕截图
错误信息
【问题讨论】:
-
你的意思是使用
getLocations.pipe(map(lt => lt.name)).subscribe(name => console.log(name))? -
@Pieterjan 我试过这个并且它返回 undefined onthe conslose。
标签: javascript node.js angular mongodb frontend