2

Setup:

 1. ionic: 3.20.0
 2. AngularFire2 V5.0.0-rc6
 3. Cordove: 8.0.0
 4. firebase: "^4.12.0"

I try to retrieve data from my database like this:

import { AngularFireDatabase, FirebaseListObservable} from 'angularfire2/database';

Where FirebaseListObservable has no exported member 'FirebaseListObservable'

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

   constructor(
      public db: AngularFireDatabase
    ){

       this.items = db.list('/restaurant_menu');
       console.log('check', this.items);
    }
}

And in the html template:

<ion-list>
    <ion-item class="text" *ngFor="let item of items">
        {{item}}
    </ion-item>
</ion-list>

But this returns me: Error: Cannot find a differ supporting object '[object Object]'

And the console.log shows me this:

{query: Reference, update: ƒ, set: ƒ, push: ƒ, remove: ƒ, …}
auditTrail:ƒ (events)
push:ƒ (data)
query:Reference {repo: Repo, path: Path, queryParams_: QueryParams, orderByCalled_: false}
remove:ƒ remove(item)
set:ƒ dataOperation(item, value)
snapshotChanges:ƒ (events)
stateChanges:ƒ (events)
update:ƒ dataOperation(item, value)
valueChanges:ƒ (events)
__proto__: Object
8
  • console.log('check', this.items); is show something or not ??? Commented Mar 25, 2018 at 12:00
  • Edited my post. Commented Mar 25, 2018 at 12:12
  • ` console.log('check', this.items);` don't work with observables. You need subscribe to get the data Commented Mar 25, 2018 at 12:32
  • this.items.subscribe(res=>console.log(res)) Commented Mar 25, 2018 at 12:35
  • @Hareesh It returns me this: TypeError: this.items.subscribe is not a function Commented Mar 25, 2018 at 12:40

3 Answers 3

3

Here is how Angularfire2 doc says

import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';

export class HomePage {
   itemsRef: AngularFireList<any>;
   items: Observable<any[]>;

   constructor(
      public db: AngularFireDatabase
    ){

       this.itemsRef = db.list('restaurant_menu');
       this.items = this.itemsRef.valueChanges();
       this.items.subscribe(res=> console.log(res));
    }
}

You can check the doc

Sign up to request clarification or add additional context in comments.

Comments

1

You can store the observable (valuechanges) in a variable then use the async tag.

   items$: Observable<any[]>;
  constructor(public db: AngularFireDatabase){
       this.items$ = this.db.list('/restaurant_menu').valueChanges();
    }

In your html

<ion-list>
    <ion-item class="text" *ngFor="let item of (items$ |async)">
        {{item}}
    </ion-item>
</ion-list>

Comments

-1

Since RxJS 6 you can use the from() operator like:

getUsers(): Observable<firestore.DocumentSnapshot<firestore.DocumentData>> {
    return from(this.db.collection('users').get());
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.