错误TypeError:无法读取未定义离子4的属性“ on”

时间:2019-10-08 20:48:02

标签: typescript firebase firebase-realtime-database ionic4

在离子3中似乎工作正常,但在离子4中引发了上述错误。 下面是代码,如果有人可以帮助解决此问题,我将不胜感激,因为我已经纠缠了数小时试图解决该问题。

profile.service.ts

import { Injectable } from '@angular/core';
import firebase from 'firebase';

@Injectable()
export class ProfileService {

  public userProfile: firebase.database.Reference;

   constructor() {
    firebase.auth().onAuthStateChanged( user => {
      if (user) {
        this.user = user;


        this.id = this.user.uid;

        this.userProfile = firebase.database().ref(`driverProfile/${user.uid}/userInfo`);

        });     
}


     getUserProfile(): firebase.database.Reference {
       return this.userProfile;



 }

home.ts

constructor(public ph: ProfileService) {
     this.ph.getUserProfile().on('value', userProfileSnapshot => {
        if (userProfileSnapshot.val() != null) {
          this.earnings = userProfileSnapshot.val().refEarnings;
          this.randomCode = userProfileSnapshot.val().id;
          console.log(this.randomCode);
        } else {
          this.earnings = 0;
        }

        this.pop.hideLoader();
      });

home.html

 <div class='bars'>

      <ion-button class="bars-price">
        <ion-icon color='primary' slot="start" name="key"></ion-icon>
        <div id="cash">{{randomCode}}</div>
      </ion-button>
    </div>
 <ion-title class="ion-padding" class="ion-text-center"><strong>Referal Earnings</strong></ion-title>
  <h1 class="ion-text-center">{{settings.appcurrency}} {{earnings}} </h1>

0 个答案:

没有答案