0
votes

I'm having a problem get information from Firebase using angularfire2 and firebase.

Packages:

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

"firebase": "^4.12.1",

Home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AngularFireDatabase, FirebaseListObservable } from "angularfire2/database-deprecated";


@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})



export class HomePage {
  books: FirebaseListObservable<any[]>;

  constructor(public navCtrl: NavController, angFire: AngularFire) {
    this.books = angFire.database.list('/Books');
  }
  }

Home.html

<ion-header>
  <ion-navbar>
    <ion-title>
      BookList Test
    </ion-title>
    <ion-buttons end>
      <button ion-button icon-only="addSong()">
        <ion-icon name="add"></ion-icon>
      </button>
    </ion-buttons>
  </ion-navbar>
</ion-header>

<ion-content padding>
<h4>Book List With Firebase</h4>
<ion-list>
  <ion-item *ngFor="let book of books  | async">
  {{book.title}}
  {{book.author}}
</ion-item>
</ion-list>
</ion-content>

Thank You.

1

1 Answers

0
votes

You still have work to do to get the data. In home.ts remove the code in your constructor & do the following:

export class HomePage {
  books: FirebaseListObservable<any[]>;

  constructor(public navCtrl: NavController, private angFire: AngularFire) {}
    ngOnInit() {
       this.books = this.angFire.list('/Books').valueChanges();
  }
  }

Now books is the observable that will emit your data. Use it in html with async pipe.