我使用Angular4(4.3.6)和AngularFire2(4.0.0-rc.2)。我得到了详细信息数据视图:
// 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 :(得分: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);
}