Firebase Subscribe to Database not working

I should start out by saying I am new to Ionic and I am trying to learn Ionic through the various tutorials online. I have run into an issue and cannot get past it. I am setting up a simple chat application and can push messages to firebase through…

this.db.list('/chat').push({
  		username: this.username,
  		message: this.message
  	})

When I attempt to pull data back through…

this.db.object('/chat/').subscribe( data => {
        console.log(data);
      })

I get the following error…

Runtime Error
Uncaught (in promise): TypeError: this.db.object(…).subscribe is not a function TypeError: this.db.object(…).subscribe is not a function at new ChatPage

I have the following in the import section of the .ts file…

import { AngularFireDatabase, FirebaseListObservable } from ‘angularfire2/database’;

I’ve been trying a bunch of different methods, but nothing seems to work. Any help would be appreciated.

Thanks,
Ben

try

this.db.list('/chat/').subscribe( data => {
        console.log(data);
      })

Note angularfire2 has recently changed https://github.com/angular/angularfire2/blob/master/docs/version-5-upgrade.md

hth
Tim

What version of AngularFire2 are you using? In version 5RC they changed the database API, FirebaseListObservable and FirebaseObjectObservable were removed in favor of AngularFireList and AngularFireObject.

Go through their docs, there were a few breaking changes (all of them in the Database API).

Tim,

Thanks for the suggestion. It still failed…

Runtime Error
Uncaught (in promise): TypeError: this.db.list(…).subscribe is not a function TypeError: this.db.list(…).subscribe is not a function at new ChatPage

Jave,

I am thanks for the reply, I am running…

"angularfire2": "^5.0.0-rc.2",

I’ll go through the docs and reply with an update.

Thanks,
Ben

You could always use a

firebase.database().ref('chat')

Could you not? The two are essentially synonymous if I understand correctly. But I may not.

@tja2353 you posted the outdated subscribe logic

This is the new syntax

constructor(afDb: AngularFireDatabase) {
  afDb.list<T>('items').valueChanges().subscribe(console.log);
}

Thanks for the new logic @LoLStats , that did the trick!!

Ben

its showing errors.

Object(...) is not a function

my applied code was
this.database.list<Review>('reviews').valueChanges().subscribe(console.log);

db.list(’/car_types/’).valueChanges().subscribe( data => {
console.log(data);
})