代码是添加项目列表,但无法从数据库获得任何数据
问题描述:
我在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"}}
答
//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>
我试图同获得。没有为我工作。 –
@rohanpadwalkar whats in your page.html? –
我的page.html –