代码正在添加项目到列表但无法从db

时间:2017-10-15 18:24:04

标签: firebase-realtime-database ionic2 angularfire2

我在Ionic2中使用AngularFire2,其中我试图获取列表并使用ngFor在视图中显示它并将新项目推送到firebase,我的代码正在添加项目以便列出但无法获取任何数据来自db。 以下是服务

constructor(public afd:AngularFireDatabase) {}

getShoppingItems(){

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

}
在console.log(Array.from(this.getShoppingItems())之后

我得到以下结果。

以下是db中希望得到回应的数据

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

1 个答案:

答案 0 :(得分: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>