2017-07-29 6 views
0

私は、すべてのユーザーのuidとデータを選択する方法はuid、イオンFirebase

enter image description here

でデータを保存usersProfileテーブルを持っていますか? 承認されたユーザーのデータのみを選択できます。

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

答えて

1

firebaseを使用する場合は、このarticle firstを読む必要があります。まず、Ionicプロジェクトにfirebaseを追加する必要があります。 インストール& JavaScriptでの設定は、リアルタイムデータベースJavaScript SDKを初期化します。

ちょうどあなたのapp.module.tsでnpm install firebase

がfirebase configオブジェクトを作成します:

// 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のマニュアルを参照してください。あなたはhere

見つけることができる

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

詳細情報:あなたはfirebaseインポートし、データベースへの要求を行うことができることをあなたの内側の角度サービス後

関連する問題