【问题标题】:How to select all users data, Ionic Firebase如何选择所有用户数据,Ionic Firebase
【发布时间】:2018-01-05 13:28:10
【问题描述】:

我有 usersProfile 表,通过 uid 保存数据

如何选择所有用户的uid和数据? 我只能选择授权用户数据。

getUsersData(token: string) {
    const userId = this.authService.getActiveUser().uid;
    return this.http.get('https://mainapp.firebaseio.com/usersProfile/' + userId + '.json?auth=' + token)
        .map((response: Response) => {
            const usersData: UsersData[] = response.json() ? response.json(): [];                
            return usersData;
        })    
        .do((userData : UsersData[]) => {
            if (userData) {
                this.usersData = userData;
            }
            else {
                this.usersData = [];                
            }
        })
}

【问题讨论】:

    标签: typescript firebase ionic-framework firebase-realtime-database


    【解决方案1】:

    如果你想使用 firebase,你必须阅读这个article first。首先,您需要将 firebase 添加到您的 Ionic 项目中,然后 JavaScript 中的安装和设置初始化实时数据库 JavaScript SDK。

    只要npm install firebase

    在你的 app.module.ts 中创建 firebase 配置对象:

    // Set the configuration for your app
    // TODO: Replace with your project's config object
    var config = {
      apiKey: "apiKey",
      authDomain: "projectId.firebaseapp.com",
      databaseURL: "https://databaseName.firebaseio.com",
      storageBucket: "bucket.appspot.com"
    };
    firebase.initializeApp(config);
    
    // Get a reference to the database service
    var database = firebase.database();
    

    您可以在Firebase console 中找到所有设置。有关详细信息,请阅读 Firebase 文档。

    在您的角度服务中,您可以导入 firebase 并对数据库进行请求:

    import * as firebase from 'firebase';
    
    // Service declaration here
    // code here ...
    
    getUsersData() {
        const userId = this.firebase.auth().currentUser.uid;
        return firebase.database().ref('usersProfile')
                                .once('value')        
                                .then(snapshot => snapshot.val())    
                                .then(users => console.log(users));
    }
    

    更多信息您可以找到here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-20
      • 1970-01-01
      • 2013-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多