Toast not working.I have been creating a simple ionic app using firebase to handle my login. When the user enters correct email and password, it logs in and a toast message show to say logged in. When the email or password is incorrect the toast message to inform the user wont pop up.
Login.html
<!--
Generated template for the LoginPage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar>
<ion-title> <img src="../../assets/imgs/leaf.png" alt="couldn't load"></ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-item>
<ion-label floating>Email Address</ion-label>
<ion-input type="text" [(ngModel)]="user.email"></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Password</ion-label>
<ion-input type="password" [(ngModel)]="user.password"></ion-input>
</ion-item>
<button ion-button (click)="login(user)">Login</button>
<button ion-button color="light" (click)="register()">Register</button>
<button ion-button (click)="information()">Information</button>
</ion-content>
Login.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ToastController } from 'ionic-angular';
//import { Loginbutton } from '/Loginbutton';
import { HomePage } from '../home/home';
import { User } from "../../models/user";
import { RegisterPage } from "../register/register";
import { InformationPage } from "../information/information";
import { AngularFireAuth} from 'angularfire2/auth';
import { ToastController } from 'ionic-angular';
/**
* Generated class for the LoginPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-login',
templateUrl: 'login.html',
})
export class LoginPage {
user = {} as User;
constructor(private aFauth: AngularFireAuth, public toastCtrl: ToastController,
public navCtrl: NavController, public navParams: NavParams) {
}
openHomePage(){
this.navCtrl.setRoot(HomePage);
}
async login(user: User) {
try{
const result = await this.aFauth.auth.signInWithEmailAndPassword(user.email, user.password);
if(result){
this.navCtrl.setRoot(HomePage);
let toast = this.toastCtrl.create({
message: 'Successfully Logged In',
duration: 3000
});
toast.present();
}
else {
let toast = this.toastCtrl.create({
message: 'Incorrect Email/Password',
duration: 3000
});
toast.present();}}
catch (e) {
console.error(e);
}
}
register(){
this.navCtrl.push(RegisterPage);
}
information(){
this.navCtrl.push(InformationPage);
}
}
The toast is in the else statement at the bottom.