Ionic2 RC 4 ionViewWillLeave not invoked


#1

I am using Ionic 2 RC 4, and cannot get the Lifecycle Hooks to invoke.

Has this changed in RC4 perhaps?

My code is as follows and neither of ionViewWillLeave or setUpUser is invoked after loginGoogle is called.:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { FirebaseAuth, AuthProviders, AuthMethods } from 'angularfire2';
import { SearchJobsPage } from '../searchjobs/searchjobs';
import { JobModel } from '../model/jobModel';
import { PersonModel } from '../model/personModel';
import { UtilityService } from '../utils/utilityService';
import { PersonService } from '../service/personService';

@Component({
  templateUrl: 'login.html'
})
export class LoginPage {
  jobModel: JobModel;
  personModel: PersonModel;

  constructor(private nav: NavController, public auth: FirebaseAuth, public utilityService: UtilityService, public personService: PersonService) {
  }

  ionViewWillLeave() {
    alert('ionViewWillLeave');
  }

  setUpUser() {
    alert('setUpUser');
    console.log('LoginPage', window.localStorage.getItem('uid'));
    let promisePersonModel: Promise<PersonModel> = this.personService.getPersonByUid(window.localStorage.getItem('uid'));
    promisePersonModel.then((personModel: PersonModel) => {
      this.personModel = personModel;
      if (!this.personModel) {
        this.personModel = new PersonModel();
        this.personModel.uid = window.localStorage.getItem('uid');
        this.personModel.emailAddress = window.localStorage.getItem('email');
        this.personModel.userName = window.localStorage.getItem('displayName');
        this.personModel.avatar = window.localStorage.getItem('photoURL');
        this.utilityService.login(this.personModel);
        console.log('LoginPage. logged in', this.personModel);
        this.personService.savePerson(this.personModel).then((personModel: PersonModel) => {
          console.log('LoginPage.saved personModel', personModel);
        });
      }
    });
  }

  loginGoogle() {
    this.auth.login({
      provider: AuthProviders.Google,
      method: AuthMethods.Redirect
    }).then((Data) => {
      console.log('LoginPage.loginGoogle()', window.localStorage.getItem('uid'), Data);
      this.setUpUser();
      this.nav.setRoot(SearchJobsPage);
    }).catch((error) => {
      console.log(error);
    })
  }

}

#2

Hmm not able to break it. Seems to be working fine for me in my test. Could you pin point anything that could be causing the error?


#3

I worked out why. The reason is the Firebase Login was doing a Redirect (AuthMethods.Redirect). If I change it to a Popup it then invokes ionViewWillLeave.