Reputation: 3801
i have a list of objects (users) in Firebase.
Every object looks like this:
And i want get 'banned' value for user.
Now my func looks like this:
isBanned() {
return this.db.object(`users/${this.authState.uid}/banned`)
}
and it's return nothing. How should i write this correctly?
I'm using angular 5 and AngularFire2.
Thanks for help.
Upvotes: 0
Views: 789
Reputation: 6981
The core of the problem is that authState is async. I'd recommend you rewrite this as an Observable mapped from AngularFireAuth's authState:
this.isBanned$ = this.afAuth.authState.switchMap(u => u ? this.db.object(`users/${u.id}/banned`).valueChanges() : Observable.of(undefined))
Upvotes: 1
Reputation: 18585
It's possible your .onAuthStateChanged
asynch method has not resolved when this function gets fired. Try and see by console'ing out the ${this.authState.uid}
from within that function. If it's null
that's your issue (asnych issue)
Assuming you do have the uid
, try and just get the whole parent node then snap.val().banned
.
Upvotes: 1