I am having trouble accessing the toast variable from the constructor in order to toast errors. It keeps showing as undefined, and I'm not sure why. This issue seems to only occur in this class, which is strange. The error message reads "ERROR TypeError: Cannot read property 'toastCtrl' of undefined". Any assistance would be greatly appreciated.
//Imports
import {
Component,
ChangeDetectorRef
} from '@angular/core';
import {
NavController,
NavParams,
Platform,
ToastController
} from 'ionic-angular';
import {
Keyboard
} from '@ionic-native/keyboard';
import {
Storage
} from '@ionic/storage';
import {
fireUser
} from './../../objects/firebaseStructures';
import {
MySegService
} from './../../services/myseg-api.service';
//Component
@Component({
selector: 'page-login',
templateUrl: 'login.html',
})
export class LoginPage {
// Login details
email: string;
emailTest: string;
loggedUser: fireUser;
password: string;
passwordTest: string;
responseMessage: string;
success: boolean = false;
uid: string;
user: string;
registerUserPage = RegisterUserPage;
forgetpass = ForgetPasswordPage;
constructor(public navCtrl: NavController, public navParams: NavParams, public mysegService: MySegService, private platform: Platform,
private keyboard: Keyboard, private storage: Storage, private toastCtrl: ToastController) {
this.loggedUser = new fireUser(null, null, null, null, null, null, null, null, null, null, null, null, null, null); //user initialization
}
signInUser() {
var user2: string;
this.mysegService.loginUser(this.email, this.password).then(res => {
console.log(res);
})
.catch(function (error) {
// Handle Errors here.
//unsuccessful log in
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === 'auth/wrong-password') {
let toast = this.toastCtrl.create({
message: 'wrong password',
duration: 3000,
position: 'top'
});
toast.onDidDismiss(() => {
console.log('Dismissed toast');
});
toast.present();
} else {
// alert(errorMessage);
}
console.log(error);
});
}
}