Magellan
Magellan

Reputation: 1226

How to display list of all other users with details from firebase excluding currently logged in user?

This code currently displays all users, including the logged users, accessing this data for display (Search in the future).

Typescript:

public ngOnInit(): void {
    if (this._auth$.authenticated) {
      //=================================================//
      // Get all users Except current user
      //=============================================//
      this.users = this.all_data;
      console.log(this.users);
    }
}

HTML:

<div class="col-sm-6 offset-md-3">
    <section class="centered-form">
      <img id="displayImage" [src]="user.ProfileImage.image" alt="profile Image">
      <h5>Full Name: {{user.profile.fullName}}</h5>
      <p>
        <br/>Age: {{user.profile.age}}
      </p>
    </section>
</div>

Upvotes: 1

Views: 969

Answers (2)

Magellan
Magellan

Reputation: 1226

So I did something that worked for me. Looped through each data object within the array and checked for the key then saved it to a new array before returning it to the view.

 this.all_data.subscribe(users => {
    var data = [];
    users.forEach(user => {
      if (user.$key !== this._auth$.id) {
        console.log(user);
        data.push(user);
      }
    });
    this.users = data;
  });

Upvotes: 0

Roman C
Roman C

Reputation: 1

Somthing like this

this.users = this.all_data.filter(user => !isAuthenticated(user));

Upvotes: 3

Related Questions