I need to display all the users that were created in the firebase

I tried to make a list of observable but it didn't show anything

export class UsersListComponent implements OnInit {
  users: Observable<any[]> ;

  constructor(db2: AngularFireDatabase) {
    this.users = db2.list('/users').valueChanges();

          }

and here is my HTML

<ul>
  <li *ngFor="let user of users | async">
     {{ user | json }}
  </li>
</ul>

I don't get anything shown on the screen here is my database firebase enter image description here

1 Answers

0
Frank van Puffelen On

Your code uses AngularFireDatabase, which is a class to load data from the Realtime Database. But your screenshot shows that you store the data in Cloud Firestore. While both databases are part of Firebase, they are completely independent and have separate APIs. So your code is reading from the Realtime Database, while the data is stored in Cloud Firestore.

From the AngularFire2 documentation on reading data from collections, it seems you'll need something like this:

this.usersCollection = afs.collection<>('users')
this.users = this.itemsCollection.valueChanges()

I highly recommend reading the AngularFire2 documentation for Cloud Firestore before continuing. It's not that much, and will save you a lot of time going down the wrong path.