Home » Javascript » Accessing a function in Angular 5

Accessing a function in Angular 5

Posted by: admin August 19, 2018 Leave a comment

Questions:

I have created a function to find out the “role” of someone. From this I then want to be able to log the users role in the console. This is the function:

  getUserRole() {
    return this.afAuth.authState.switchMap((auth: any) => {
      this.usersCollection = this.afs.collection<any>('users');
      this.userDoc = this.usersCollection.doc(auth.uid);
      this.user = this.userDoc.valueChanges();
      return this.user.map(user => {
        return user.role;

      });
    });
  }

I have tried doing console.log(user.role) however this does not seem to work. Does anyone know how to do this?

Answers: