如何使用Angular从Firebase检索具有用户ID的数据?

时间:2018-08-10 13:38:13

标签: angular firebase firebase-realtime-database

如何使用 UserId 从Firebase获取当前用户的数据? 我收到的响应为空。我似乎无法正确执行此操作,请帮助。 预先感谢。

import { Component, OnInit } from '@angular/core';
import { AngularFireDatabase, AngularFireList, AngularFireObject } from 
'angularfire2/database';

import { Profile } from '../services/profile/profile.model';
import { AngularFireAuth } from '../../../node_modules/angularfire2/auth';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})

export class HomeComponent implements OnInit {

constructor(private angularFireDatabase: AngularFireDatabase,
private angularFireAuth : AngularFireAuth) {
  this.getUserProfile();
}

ngOnInit() {

}

 getUserProfile()
 {
  this.angularFireAuth.authState.subscribe(user => {
     this.angularFireDatabase.object('/profiles/' + 
       user.uid).valueChanges().subscribe(profile => {
       console.log(profile)
     })
  })
}
}

这是我的数据库结构:

Here's my Database structure

0 个答案:

没有答案