我在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"}}
答案 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>