Using UID as a variable for angularfire2 list name in firebase, but it was undefined in the firebase


#1

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}`);
     
    }

in the apps, user was supposed cannot see the data of another user, but again because $this.UserID cant be read for some whatever reason, another user can see the data of other user.


#2

I got the same problem, any help?