Reputation: 11
I can’t use a variable to hold the name of my list on firebase.
After I push some data the variable becomes undefined in firebase.
$this.UserID
is meant to hold the UID but it can't be read.
My code:
private referenceListRef;
UserID: string;
constructor(private http: Http,
private db: AngularFireDatabase,
private ofAuth: AngularFireAuth,
public storage: Storage
) {
this.ofAuth.authState.take(1).subscribe(data => {
this.UserID = data.uid;
console.log(`user id : ${this.UserID}`);
})
this.referenceListRef = this.db.list(`${this.UserID}`);
}
Upvotes: 1
Views: 39
Reputation: 4513
You need to add referenceListRef
inside subscribe()
, because you don't have this.UserID
before this.ofAuth.authState
Observable's completes.
private referenceListRef;
UserID: string;
constructor(private http: Http,
private db: AngularFireDatabase,
private ofAuth: AngularFireAuth,
public storage: Storage
) {
this.ofAuth.authState.take(1).subscribe(data => {
this.UserID = data.uid;
console.log(`user id : ${this.UserID}`);
this.referenceListRef = this.db.list(`${this.UserID}`); // <-- This code
})
}
Upvotes: 1