0
anglefire 2를 처음 사용하면서 문제가 발생했습니다. 나는 firebase의 구름 밭에 저장되어있는 음식점들을 가지고있다. 나는 제대로 레스토랑의 목록을 얻을하고 표시 할 수 있어요,하지만 난에 액세스하고 별도의 변수에 특정 레스토랑을 저장하려고하면, 내가에서 데이터를 얻을 수가 질수있는 관측 반환angularfire2 스냅 샷 데이터
items: Observable<any[]>;
tester: any[] = [];
private test: AngularFirestoreCollection<any>;
constructor(db: AngularFirestore){
this.test = db.collection<any>('restaurants')
// this.items = db.collection('restaurants').valueChanges();
this.items = this.test.snapshotChanges().map(actions => {
return actions.map(a => {
const data = a.payload.doc.data();
this.tester.push(data); //This returns an observable instead of an array
const id = a.payload.doc.id;
return { id, ...data };
});
});
}
getRestaurants(){
return this.items;
}
//Here I want to be able to return the item object
getRestaurant(index){
console.log(this.tester[i]);
}
을
구성 요소 코드 나 중포 기지의 반환 관찰 가능한 목록에서 데이터를 추출 할 수있는 방법을 이해하는 데 어려움을 겪고
constructor(private restService: RestaurantService){}
restaurants = <any>[];
selectedRestaurant: any;
ngOnInit(){
this.restaurants = this.restService.getRestaurants()
}
onSelect(index){
console.log(this.restService.getRestaurant(index));
}
임.
snapshot()을 사용해야합니까? valuechanges()를 사용하기가 더 쉽기 때문입니다. 내가 너에게 예제를 줄 수있어. – Makah