2017-09-21 3 views
2

저는 Angular4 (4.3.6) 및 AngularFire2 (4.0.0-rc.2)를 사용합니다.AngularFire2 - db.object로 단일 개체 가져 오기 - 데이터가 늦게 수신 됨

// GET THE ID 
this.id = this.route.snapshot.params['id']; 

this.subscriptions.push(
    this.db.object('/restaurants/' + this.id).subscribe(data => { 
    this.restaurant = data; 
    console.log(data); 
    }) 
); 

이러한 방법으로, 나는 데이터를 얻을 수 있지만, 콘솔 던져 오류는 데이터가 너무 조금 늦게 오기 때문에 : 내가 가진 자세히보기에 대한 데이터를 얻을. 마침내 나는 route.params에서 ID를 얻고 싶지 않습니다. 나중에 객체 이름을 상세 뷰의 경로로 사용하기를 원하기 때문입니다. 여기

StackBlitz : https://stackblitz.com/edit/angular-7gabaq?file=sites/site-restaurant-detail/site-restaurant-detail.component.ts ("보기 식당"을 클릭)

답변

0

항목을 만들 때 사용자 지정 키를 만드는 시도 할 수 있습니다 : 경로 = restaurants/${res_name}

newForm(res_name: string, data_1: string, data_2: string) { 
const path = `restaurants/${res_name}`; // Endpoint on firebase 
const userRef: AngularFireObject<any> = this.db.object(path); 
const data = { 
    restaurant: res_name, 
    some_data: data_1, 
    onether_data: data_2 
}; 
userRef.update(data) 
    .catch(error => console.log(error); 

}