背景
我正在使用带有 "@angular/fire": "^5.0.2" 的 ionic 4
问题
我想列出配置文件节点下的所有值,这是我的 firebase 结构:
我想获取密钥、位置、所有者名称和恢复名称。稍后我将使用该密钥打开另一个节点。对于下面的代码,我想显示位置、所有者名称和恢复名称。
我的代码
在home.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ToastController } from 'ionic-angular';
import { AngularFireAuth } from '@angular/fire/auth';
import { AngularFireDatabase, AngularFireList } from '@angular/fire/database';
import { UserProfile } from './../../models/user-profile';
import { RestoProfile } from './../../models/resto-profile';
@IonicPage()
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
restoProfileData: AngularFireList<RestoProfile[]>;
restoProfileRef: AngularFireList<RestoProfile[]>;
constructor(private afAuth: AngularFireAuth, private afDatabase: AngularFireDatabase,
private toast: ToastController,
public navCtrl: NavController, public navParams: NavParams) {
}
ionViewDidLoad() {
this.afAuth.authState.subscribe(data => {
if(data && data.email && data.uid){
this.toast.create({
message: `Welcome to brianApp-customer, ${data.email}`,
duration: 3000
}).present();
this.restoProfileRef = this.afDatabase.list<RestoProfile>(`profile/`);
this.restoProfileData = this.restoProfileRef.snapshotChanges();
}
else {
this.toast.create({
message: `Could not find authentication details`,
duration: 3000
}).present();
}
});
}
}
在home.html中
<ion-list>
<ion-item *ngFor="let data of restoProfileData | async">
<h2>Key: {{ data.payload.key }}</h2>
<h2>Location: {{data.payload.val().location}}</h2>
<h2>ownerName: {{data.payload.val().ownerName}}</h2>
<h2>restoName: {{data.payload.val().restoName}}</h2>
</ion-item>
</ion-list>
此代码导致Object(...) is not a function
.
任何帮助,将不胜感激。谢谢