如何选择所有用户数据,Ionic Firebase [英] How to select all users data, Ionic Firebase

查看:43
本文介绍了如何选择所有用户数据,Ionic Firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have usersProfile table, where save data by uid

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

How to select all users uid and data? I can select only Authorized users data.

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 = [];                
            }
        })
}

推荐答案

如果要使用Firebase,则必须阅读文章优先.首先,您需要将Firebase添加到Ionic项目中,然后安装与安装JavaScript中的安装程序会初始化实时数据库JavaScript SDK.

If you want use firebase you must read this article first. First of all you need add firebase to your Ionic project and Installation & Setup in JavaScript initialize the realtime database JavaScript SDK.

只需执行 npm安装firebase

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

In your app.module.ts create firebase config object:

// 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控制台中找到所有设置.有关更多信息,请阅读Firebase文档.

You could find all setting in your Firebase console. For more information read Firebase documentation.

在此之后,您可以在角度服务中导入firebase并向数据库提出请求:

After that inside you angular service you could import firebase and do request to database:

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

更多信息,您可以在此处

这篇关于如何选择所有用户数据,Ionic Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆