2017-07-29 70 views
0

我有usersProfile表,其中通过UID如何选择所有用户数据,离子火力地堡

enter image description here

保存数据如何选择所有用户的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 = [];     
      } 
     }) 
} 

回答

1

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

只是做npm install firebase

在你app.module.ts创建火力配置对象:

// 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文档。

之后,你的角度服务里面,你可以导入火力和做请求数据库:

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