Nico
Nico

Reputation: 154

Ionic 2 + Firebase - loading userdata takes 30-60 seconds

I am building an Ionic 2 + Firebase application, but now I am stuck for a while. I cannot determine the issue with this.

I am loading the data from firebase. On console, I can see that it is working fine (loading time max 1 second).

But, then it takes up to 60 seconds for the data to be displayed on the app UI.

Find the console output with the userdata here.

Code:

HTML:

<ion-content padding>
    <ion-list>
        <ion-item *ngFor="let item of items">
            <h2>{{item?.birthDate}}</h2>
            <p>Ticket: <strong>{{item?.username}}</strong></p>
            <p>Date: <strong>{{item?.email}}</strong></p>
        </ion-item>
    </ion-list>
</ion-content>

profile.ts:

  ionViewDidEnter() {
    this.authData.getUserProfile().on('value', snapshot => {
      let rawList = [];
      rawList.push({
        birthDate: snapshot.val().birthDate,
        email: snapshot.val().email,
        gender: snapshot.val().gender,
        password: snapshot.val().password,
        phone: snapshot.val().phone,
        username: snapshot.val().username,
        weight: snapshot.val().weight
      });
      this.items = rawList;
      console.log(this.items);
      console.log(rawList);
    });

  }

auth Service:

  public userProfileData: any;
  public currentUser: any;

  constructor(public af: AngularFire) {
    af.auth.subscribe(user => {
      if (user) {
        this.currentUser = firebase.auth().currentUser.uid;
        this.fireAuth = user.auth;
        this.userProfileData = firebase.database().ref(`users/${this.currentUser}/`);
      }
    });
  }
  getUserProfile(): any {
    return this.userProfileData;
  }

Upvotes: 2

Views: 346

Answers (1)

mois rip
mois rip

Reputation: 26

I would suggest you to try new syntax. I can send you a good example wich would help you quite a lot i think.

https://github.com/javebratt/event-tutorial

Check out this

Upvotes: 1

Related Questions