我如何设置列表,并在角度4 firebase

问题描述:

我推出了一些列项目...我想从文本框中的字段推一些值,并设置一些值与默认值添加项目我如何设置列表,并在角度4 firebase

我总是用这

addResturant(resturant: resturant) { 
    return this.resturants.push(resturant) 
} 

,餐厅包含一些细节我想

set(resturant.branches,'') also set(resturants.items,'') 

我在哪里可以把它们放在同一方法要在按压BTN节省产生的?

这里是数据库结构 enter image description here

+0

如何您的数据在Firebase中?你能向我们展示一些内容来看看结构吗?我并不认真考虑你的问题。你可以做一个例子或者添加一些代码 – Wandrille

+0

嗯,我想创建一个名为items和branches的空节点...所以这是我知道创建一个名为items和called branches的空节点的唯一方法......所以我想添加新的餐厅......使用免费值创建的项目和分支节点......以及其他餐馆的按键和值通常像餐厅名称,resturantdesc等一样推入数据库。 @Wandrille –

+0

并且在您的firebase数据库中,对于餐厅,它是否包含生成的密钥列表? – Wandrille

更好的结构将是:

在组件

constructor(private resturantService:ResturantService){} 

yourPushButton(resturant){ 
    // I presume resturant is an object 
    resturant['branches']=''; 
    resturant['items']=''; 
    this.resturantService.pushResturant(resturant) 
} 

而且在服务ResturantService:

constructor(private db: AngularFireDatabase){} <--- if you use angularFire2 

pushResturant(resturant){ 
    const itemsRef = this.db.object('resturants/${resturant.name}') 
    itemsRef.update(resturant) 
} 
+0

哦,它不是一个对象,它是一个列表! –

+0

当您添加新的餐厅时,这将是一个对象,而不是一个列表。你有一份餐厅清单。您想一次添加多个餐厅吗? – Wandrille

+0

好,你能告诉我如何获得一个对象吗?我总是用这个来获得一个列表。 –