這是我的實時資料庫我想找到連接的人的文章并顯示資訊

這是我的 ionic 腳本頁面
這是我的匯入,我可以檢索要連接的用戶的 ID,但無法在實時資料庫中檢索此資訊
import { Component } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/compat/auth';
import { AngularFireDatabase, AngularFireList } from '@angular/fire/compat/database';
export class Tab3Page {
public profileData: any;
name: string;
prenom: string;
constructor(private afAuth: AngularFireAuth,
private db: AngularFireDatabase,
private toast: ToastController,
private navCtrl: NavController,
private authService: FirebaseAuthServiceService) {
this.afAuth.authState.subscribe(
(res)=>{
this.profileData = res.uid;
console.log(this.profileData);
}
)
this.db.list("users/" this.profileData).valueChanges().subscribe(details => {
this.name =details["name"];
this.prenom = details["prenom"];
console.log(details);
})
}
}
uj5u.com熱心網友回復:
很難確定,但我有一種感覺,您是在用戶登錄之前附加資料庫偵聽器。要解決此問題,您需要將 subscribe 呼叫移至 auth 狀態偵聽器”
this.afAuth.authState.subscribe(
(res)=>{
this.profileData = res.uid;
console.log(this.profileData);
}
this.db.list("users/" this.profileData).valueChanges().subscribe(details => {
this.name =details["name"];
this.prenom = details["prenom"];
console.log(details);
})
)
如果這確實加載了資料,您將需要開始管理資料庫訂閱,因為這authState當然可能會隨著時間的推移而改變。
uj5u.com熱心網友回復:
謝謝弗蘭克的干預我看到了我的問題,這只是區域變數的問題
this.afAuth.authState.subscribe(
(res)=>{
this.profileData = res.uid;
console.log(this.profileData);
this.db.list("users/" this.profileData).valueChanges().subscribe(details => {
this.name = details[2];
console.log(this.name);
})
}
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/340270.html
標籤:angularjs 打字稿 火力基地 离子框架 Firebase 实时数据库
