Angular Firebase数据库查询

时间:2017-06-21 13:48:49

标签: javascript angular firebase firebase-realtime-database angularfire2

这是我的.ts文件

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

@Component({
  selector: 'app-candidate-reg-success',
  templateUrl: './candidate-reg-success.component.html',
  styleUrls: ['./candidate-reg-success.component.css']
})
export class CandidateRegSuccessComponent implements OnInit {

  constructor() { 
    debugger;
    const rootRef=firebase.database.ref();
    const mail=rootRef.child('candidates_list').orderByChild('email').equalTo('pranavkeke@gmail.com');
    console.log(mail);

  }

  ngOnInit() {
  }

}

我正在尝试从candidates_list表中查询具有电子邮件地址pranavkeke@gmail.com的用户。

但我无法安慰它。它显示错误,如

  

财产' ref'类型'类型数据库'。

上不存在

查询角度firebase数据库的任何解决方案?

1 个答案:

答案 0 :(得分:0)

您需要在构造函数中注入AngularFirebaseData并更改代码并重试

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

@Component({
  selector: 'app-candidate-reg-success',
 templateUrl: './candidate-reg-success.component.html',
 styleUrls: ['./candidate-reg-success.component.css']
})
  export class CandidateRegSuccessComponent implements OnInit {

  constructor(public db: AngularFireDatabase) { 
    debugger;
    db.list('/candidates_list', ref => ref.orderByChild('email').equalTo('pranavkeke@gmail.com'));
}   
 ngOnInit() {
    }}