I am trying to navigate to another page after user is authenticated with angularfire. Everything works except navigating to another page.
Here is my code:
constructor(public navCtrl: NavController, public menu: MenuController, public afAuth: AngularFireAuth, public db: AngularFireDatabase, private platform : Platform) {
this.navigateIfUserIsLogdIn();
}
navigateIfUserIsLogdIn(){
this.authState = this.afAuth.authState;
this.user = this.afAuth.auth.currentUser;
this.afAuth.auth.onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
this.navCtrl.setRoot(HomePage);
} else {
// No user is signed in.
}
});
}
The error I get is:
Error: Uncaught (in promise): TypeError: Cannot read property 'navCtrl' of undefined
Why wont it work when inside navigateIfUserIsLogdIn() ?
please help, and provide an example :)