Reputation: 1214
I have usersProfile table, where save data by 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 = [];
}
})
}
Upvotes: 1
Views: 1643
Reputation: 470
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.
Just do npm install 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();
You could find all setting in your Firebase console. For more information read Firebase documentation.
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));
}
More information you could find here
Upvotes: 1