添加地图运算符后我得到了“未定义”
角度版本:7
地图导入:
import { map } from 'rxjs/operators';
使用地图:
this.restaurantService.getRestaurants().pipe(map((restaurant:any) => restaurant.name)).subscribe((restaurants) => {
console.log(restaurants); // undefined
});
不必要的“名称”字段在任何字段都返回undefined
没有地图
this.restaurantService.getRestaurants().subscribe((restaurants) => {
console.log(restaurants); // [{...,name: 'lorem'},{...},...]
});
服务:
getRestaurants(): Observable<_Restaurant[]> {
return this.get(api.restaurants) as Observable<_Restaurant[]>;
};
我在地图运算符中记录了餐厅,并且得到了一个应该是对象的数组
.pipe(map(restaurant => {
console.log(restaurant); //[{},{}] !!
return restaurant.name;
}))
有人知道为什么我会得到未定义的信息吗?
答案 0 :(得分:4)
hi amit POST
{ about: 'abcde',
age: 26,
email: 'test@test.com',
fbProfileLink: 'www.some-profile-link-here.com',
gender: 'male',
id: null,
imageUrl:
'https://url-url.url.url/platform/profilepic/?asid=3422352323&height=50&width=50&ext=3422352323&hash=hash',
language: { mainLang: '', speaksEnglish: true },
name: 'abcde',
residence: 'abcde' }