【发布时间】:2019-01-21 17:44:46
【问题描述】:
我有这个get方法
this.data.getCoffee(params['id'], response => {
this.coffee = response;
});
并且没有响应的是
coffeetype:"frappe"
location:Array(1)
0:{_id: "5b7327a3adcdbc1a80b7861f", address: " adres 5", city: "city5",
latitude: 21.1211546, longitude: 79.1291045}
length:1
__proto__:Array(0)
name:"coffee5 "
notes:"note5"
place:"place 5"
rating:7
tastingRating:Array(1)
0:{_id: "5b7327a3adcdbc1a80b7861e", aroma: 6, flavor: 6, intensity: 6,
aftertaste: 5}
length:1
__proto__:Array(0)
__v:0
_id:"5b7327a2adcdbc1a80b7861d"
但是当我将它保存到 this.coffee = response 的实例时 只有名字、类型、注释和整体风格才能喝到咖啡 品尝数组和位置数组没有进入咖啡的数组实例
咖啡.ts
import { TastingRating } from './TastingRating';
import { PlaceLocation } from './PlaceLocation';
export class Coffee {
_id: string;
coffeetype: string;
rating: number;
notes: string;
tastingRating: TastingRating;
constructor (
public name: string = '',
public place: string= '' ,
public location: PlaceLocation = null
) {
this.location = new PlaceLocation();
this.tastingRating = new TastingRating();
}
}
地点位置.ts
constructor(
public address: string = '',
public city: string = '',
public latitude: number = null,
public longitude: number = null,
) {
}
品尝评级.ts
export class TastingRating {
aroma: number;
flavor: number;
intensity: number;
sweetness: number;
aftertaste: number;
}
我使用 MongoDB 作为后端 如果我使用 this.coffee.location.city 它显示未定义 甚至 response.location.city 都从 get 方法中说 undefined
【问题讨论】:
-
请更好地格式化您的帖子。
标签: javascript angular mongodb observable mean