I need do this:
async doLogin(user: User) {
try {
const result = await this.AngularFireAuth.auth.signInWithEmailAndPassword(user.email, user.password);
if (result) {
this.AngularFireAuth.authState.subscribe(user => {
if (user) {
var ref = firebase.database().ref(`profile/${user.uid}`);
ref.once("value")
.then(function(snapshot) {
var key = snapshot.key;
if (user.uid === key) {
this.navCtrl.setRoot(HomePage);
}
else {
this.navCtrl.setRoot(ProfilePage);
}
});
}
});
}
}
catch (error) {
let toast = this.toastCtrl.create({
message: this.loginErrorString,
duration: 3000,
position: 'top'
});
toast.present();
}
}
But i got this error: TypeError: Cannot read property 'navCtrl' of undefined
I don't know why it does it but i think that the method doLogin can't read the module navCtrl. The navCtrl method was add to construct obviously.
Best Regards friends