ToastController not working


#1

The toastController is not showing up, I am dumbstruck, please help.

Here is the HTML.

<ion-header>
  <ion-navbar color="primary">

    <button ion-button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>

    <ion-title>Ask Ganesha</ion-title>

    <ion-buttons end>
      <button ion-button icon-only *ngIf="isFavourite" (click)="changeFavouriteState()">
        <ion-icon name="md-heart" (isActive)='false' padding></ion-icon>
      </button>
      <button ion-button icon-only *ngIf="!isFavourite" (click)Preformatted text="changeFavouriteState()">
        <ion-icon name="md-heart-outline" (isActive)='false' padding></ion-icon>
      </button>
      <button ion-button icon-only (click)="information()">
        <ion-icon name="information-circle" padding></ion-icon>
      </button>
      <button ion-button icon-only (click)="Setting()">
        <ion-icon name="settings" padding></ion-icon>
      </button>
    </ion-buttons>

  </ion-navbar>
</ion-header>

On the click of icon it should call changeFavouriteState() function which it is doing I checked by logging but it doesn’t show any toast.
Here is the changeFavouriteState:

changeFavouriteState() {

    this.isFavourite = !this.isFavourite;
    
    console.log('isFavourite: ', this.isFavourite);

    if (this.isFavourite) {
      this.toastCtrl.create({
        message: 'Page added to favourites!',
        duration: 3000,
        position: "top"
      })
    } else {
      this.toastCtrl.create({
        message: 'Page added to favourites!',
        duration: 3000,
        position: "top"
      });
    }

  }

I injected toastCtrl via this:

constructor(public navCtrl: NavController, public navParams: NavParams, private toastCtrl: ToastController) {

Please help.

EDIT 1:
I even tried to use the toastCtrl when the page loads (in the constructor), it still doesn’t show anything.


#2

You must run toast.present() function.

let toast = this.toastController.create({
            message: 'Page added to favourites!',
            duration: 3000,
            position: 'bottom',
            showCloseButton: true
        });

        toast.present();

#3

Lol such a silly mistake by me, sorry and thank you! <3