如何从firebase数据库中读取UID

时间:2017-11-21 06:45:34

标签: javascript firebase firebase-realtime-database ionic3

获得授权,如何阅读这些UID?我没有运气试过这个:

//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}}

1 个答案:

答案 0 :(得分:1)

您的问题是您分配this.user的范围。如果您使用function(),则可以创建新范围,请尝试使用lambdas/arrow functions代替:

修改

//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);
        }); 
    });
}

有关范围界定问题的更多信息,您可能需要查看at this.