gpt4 book ai didi

AngularFire2 - 使用 db.object 获取单个对象 - 数据来晚了

转载 作者:搜寻专家 更新时间:2023-10-30 21:59:43 24 4
gpt4 key购买 nike

我使用 Angular4 (4.3.6) 和 AngularFire2 (4.0.0-rc.2)。我通过以下方式获取详细 View 的数据:

// 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,因为我想稍后使用对象名称作为详细 View 的路由。

这里是 StackBlitz:https://stackblitz.com/edit/angular-7gabaq?file=sites/site-restaurant-detail/site-restaurant-detail.component.ts (点击“查看餐厅”)

最佳答案

您可以尝试在创建项目时制作自定义键:路径 = 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);

关于AngularFire2 - 使用 db.object 获取单个对象 - 数据来晚了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46352512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com