我尝试以this tutorial的形式从Firebase数据库检索数据 但我收到此错误;
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.(AngularFireList)
我想检索当前用户的特定数据(当用户登录到应用程序时)
谁能帮助我解决这个问题
此html页面
<ion-content padding>
<!-- مسسوول عن عرض البيانات -->
<ul *ngFor ="let d of datanote " class="collection" class="colorul" text-right >
<li class= "collection-item" >
<ion-card class="backgounddiv" >
<ion-card-header>
<strong class="colorli" >{{d.title}}<br></strong>
</ion-card-header>
<ion-card-content>
<strong class="colorli" >{{d.desciption}}</strong>
</ion-card-content>
</ion-card>
</li>
</ul>
</ion-content>
此ts页面
export class HomePage {
datanote :AngularFireList<users[]> ;
userId: string;
constructor(
public navCtrl: NavController,
private ev: Events,
public firestoreService:FierbaceserverProvider,
public navParams: NavParams,
private afAuth: AngularFireAuth,
private db: AngularFireDatabase
) { }
ngOnInit():AngularFireList <users[]> {
if (this.userId) return;
this.datanote=this.db.list(`note-list/${this.userId}`);
return this.datanote;
}
}
答案 0 :(得分:0)
this.datanote
目前是一个参考,它不包含数据库值,为了获取这些值,您需要等待可观察的值。
private noteList$: Subscription;
ngOnInit() {
if (this.userId) return;
this.noteList$ = this.db.list(`note-list/${this.userId}`)
.snapshotChanges()
.subscribe(snapshot => {
this.datanote = snapshot;
});
}
ngOnDestroy() {
noteList$.unsubscribe();
}
然后您应该更新HTML,以检查this.datanote
上是否存在ngIf="datanote"
和ion-content
。
<ion-content *ngIf="datanote" padding>
<!-- مسسوول عن عرض البيانات -->
<ul *ngFor ="let d of datanote " class="collection" class="colorul" text-right >
<li class= "collection-item" >
<ion-card class="backgounddiv" >
<ion-card-header>
<strong class="colorli" >{{d.title}}<br></strong>
</ion-card-header>
<ion-card-content>
<strong class="colorli" >{{d.desciption}}</strong>
</ion-card-content>
</ion-card>
</li>
</ul>
</ion-content>