Fresco
Fresco

Reputation: 363

How to read UIDs from firebase database

With granted permission, how to read these UIDs? I have tried this with no luck:

//members.ts

    export class MembersPage {
      user:any = 'wait...';

      constructor() {
        firebase.database().ref('Accounts').once('value', function(mySnap){
            mySnap.forEach(function(uiDSnapshot) {
            this.user = uiDSnapshot.key;
            console.log(this.user);
            }); 
        });
    }

enter image description here

//members.html
{{user}}

Upvotes: 1

Views: 89

Answers (1)

alex kucksdorf
alex kucksdorf

Reputation: 2633

Your problem is the scope in which you are assigning this.user. You create a new scope, if you use function(), try using lambdas/arrow functions instead:

EDIT:

//members.ts

export class MembersPage {
  user: [string] = [];

  constructor() {
    firebase.database().ref('Accounts').once('value', (mySnap) => {
        mySnap.forEach((uiDSnapshot) => {
            this.user.push(uiDSnapshot.key);
            console.log(this.user);
        }); 
    });
}

For further information on the scoping problem you might wanna take a look at this.

Upvotes: 1

Related Questions