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(點擊 「查看餐廳」)