如何选择所有用户数据,Ionic Firebase [英] How to select all users data, 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屋!