2017-10-15 21 views
0

我在Ionic2中使用AngularFire2,其中我試圖獲取列表並使用ngFor在視圖上顯示它,並且還將新項目推送到firebase,我的代碼是添加項目列表porperly,但無法從數據庫中獲取任何數據。 以下是服務代碼是添加項目列表,但無法從數據庫獲得任何數據

constructor(public afd:AngularFireDatabase) {} 

getShoppingItems(){ 

return this.afd.list('/shoppingItems'); 

} 

的console.log後(Array.from(this.getShoppingItems()))我得到以下結果。

和下面是DB數據其中M預期響應

{"shoppingItems":{"-KwW3BgGsBfd0MeMqeTL":"Rohan","-KwWAK5zrEfwCYM-KdlT":"Vikas"}} 

回答

0
//This should be in Provider.ts 

getShoppingItems(){ 

return this.afd.list('/shoppingItems'); 

} 

//In Page.ts, declear shoppingitems as an observable list 
shoppingItems: FirebaseListObservable<any[]>; 


//Still in Page.ts, inside its constuctor, call the method in provider service 
this.shoppingItems = this.provider_service.getShoppingItems(); 

//In Page.html, do this 

<ion-list *ngFor=let item of shoppingItems | async ></ion-list> 
+0

我試圖同獲得。沒有爲我工作。 –

+0

@rohanpadwalkar whats in your page.html? –

+0

我的page.html

相關問題