最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular Firebase Database Querying - Stack Overflow

programmeradmin1浏览0评论

This is my .ts file

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

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

  constructor() { 
    debugger;
    const rootRef=firebase.database.ref();
    const mail=rootRef.child('candidates_list').orderByChild('email').equalTo('[email protected]');
    console.log(mail);

  }

  ngOnInit() {
  }

}

I am trying to query the user from candidates_list table which has the email address [email protected].

But I am unable to console it. It shows a error like

Property 'ref' does not exist on type 'typeof database'.

Any solution to query angular firebase database?

This is my .ts file

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

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

  constructor() { 
    debugger;
    const rootRef=firebase.database.ref();
    const mail=rootRef.child('candidates_list').orderByChild('email').equalTo('[email protected]');
    console.log(mail);

  }

  ngOnInit() {
  }

}

I am trying to query the user from candidates_list table which has the email address [email protected].

But I am unable to console it. It shows a error like

Property 'ref' does not exist on type 'typeof database'.

Any solution to query angular firebase database?

Share Improve this question edited Jul 5, 2018 at 18:19 marc_s 757k184 gold badges1.4k silver badges1.5k bronze badges asked Jun 21, 2017 at 13:48 pranavyoyopranavyoyo 851 silver badge6 bronze badges 3
  • 1 firebase.database.ref(); => firebase.database().ref(); – Frank van Puffelen Commented Jun 21, 2017 at 14:10
  • sir when i changed like above they are showing firebase is not defined eroor?Please help me – pranavyoyo Commented Jun 21, 2017 at 14:22
  • That error message would have existed before the change too. It looks like you should use AngularFire's built-in querying capabilities: github./angular/angularfire2/blob/master/docs/… – Frank van Puffelen Commented Jun 21, 2017 at 14:42
Add a ment  | 

1 Answer 1

Reset to default 3

you need to inject the AngularFirebaseData in constructor and change the code and try again

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

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

  constructor(public db: AngularFireDatabase) { 
    debugger;
    db.list('/candidates_list', ref => ref.orderByChild('email').equalTo('[email protected]'));
}   
 ngOnInit() {
    }}
发布评论

评论列表(0)

  1. 暂无评论