ewizard
ewizard

Reputation: 2862

AngularFireDatabase list function not being called on ios ionic

I am trying to do the most basic retrieval with Ionic and AngularFireDatabase. My code is as follows:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { SignInPage } from '../signin/signin';
import { FeedUser } from '../feeduser/feeduser';
import { FeedStylist } from '../feedstylist/feedstylist';
import { Keyboard } from '@ionic-native/keyboard';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';


@Component({
  selector: 'page-sign-up',
  templateUrl: 'signup.html'
})
export class SignUpPage {
  stylist: boolean;
  user: boolean;
  items: FirebaseListObservable<any>;

  constructor(public navCtrl: NavController, public keyboard: Keyboard, public af: AngularFireDatabase) {
    this.items = af.list('/test');
    console.log(this.items);
  }

  ...

There are no errors, but nothing happens - the console message is never logged...not even null (if its not retrieving the items).

I am using Ionic 3.5.0, and iOS 10. This problem only happens on iOS device, it works in the browser. Thanks

Upvotes: 0

Views: 2471

Answers (2)

ewizard
ewizard

Reputation: 2862

Here is what ended up working:

this.items = af.list('/test');
this.items.subscribe(items => items.forEach(item => { 
  console.log(item.$value);
}));

Upvotes: 0

CharanRoot
CharanRoot

Reputation: 6325

af.list('/test') return observable so it will take some time to resolve value and return result but in your code your immediate accessing observable value before resolving observable.

you need subscribe observable and access value

example

 this.items = af.list('/test');
   this.items.subscribe(value=> {
        console.log(this.items);
    });

Upvotes: 2

Related Questions