Roberto Pinheiro
Roberto Pinheiro

Reputation: 1320

How to retrieve a list of users from firebase database with angularFire and no "key"?

I'm using angularFire to connect my page to my database. I want to display all the users stored in my firebase database in the form of a list on a page. The way I am storing these users is by their e-mail like this :

users
   |_email:name
   |   
   |_email:name
   |
   |_email:name
   |
   |_...

The problem i'm facing is that i don't know how to retrieve all the users and put on Array.

I think it's something similar to .list(), but in this duntion I would need to separate users differently, eg:

user
   |_key1
   |   |_email:value
   |   |_name:value
   |_key2
   |   |_email:value
   |   |_name:value
   |_...

I need to put this in my credentialsArray with the Credetial model, so I can list it in my table:

this.credentialsArray.push(new Credential('name', 'email'));

because I list it this way:

<tr *ngFor="let item of credentialsArray">
   <td>{{ item.name }}</td>
   <td>{{ item.email }}</td>
</tr>

How do I do it?

Upvotes: 1

Views: 1831

Answers (1)

Troy Myers
Troy Myers

Reputation: 520

From the 'user' list you can push the retrieved values into your array with a loop like this:

this.fireDB.list('user').snapshotChanges().subscribe(res => {

        res.forEach(doc => {

        this.credentialsArray.push(doc.payload.val());

    });

});

Then your html code would work fine for displaying the results.

Upvotes: 1

Related Questions