2017-09-21 8 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); 

}

関連する問題