2
我正在构建Ionic 2 + Firebase应用程序,但现在我停留了一段时间。我无法确定这个问题。Ionic 2 + Firebase - 加载用户数据需要30-60秒
我正在从Firebase加载数据。在控制台上,我可以看到它工作正常(加载时间最多1秒)。
但是,最多需要60秒才能在应用UI上显示数据。
使用userdata here查找控制台输出。
代码:
HTML:
<ion-content padding>
<ion-list>
<ion-item *ngFor="let item of items">
<h2>{{item?.birthDate}}</h2>
<p>Ticket: <strong>{{item?.username}}</strong></p>
<p>Date: <strong>{{item?.email}}</strong></p>
</ion-item>
</ion-list>
</ion-content>
profile.ts:
ionViewDidEnter() {
this.authData.getUserProfile().on('value', snapshot => {
let rawList = [];
rawList.push({
birthDate: snapshot.val().birthDate,
email: snapshot.val().email,
gender: snapshot.val().gender,
password: snapshot.val().password,
phone: snapshot.val().phone,
username: snapshot.val().username,
weight: snapshot.val().weight
});
this.items = rawList;
console.log(this.items);
console.log(rawList);
});
}
身份验证服务:
public userProfileData: any;
public currentUser: any;
constructor(public af: AngularFire) {
af.auth.subscribe(user => {
if (user) {
this.currentUser = firebase.auth().currentUser.uid;
this.fireAuth = user.auth;
this.userProfileData = firebase.database().ref(`users/${this.currentUser}/`);
}
});
}
getUserProfile(): any {
return this.userProfileData;
}