1

我推出了一些列項目...我想從文本框中的字段推一些值,並設置一些值與默認值添加項目我如何設置列表,並在角度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

回答

1

更好的結構將是:

在組件

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

好,你能告訴我如何獲得一個對象嗎?我總是用這個來獲得一個列表。 –