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);
})
}
}