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(点击 “查看餐厅”)