How to create toast message in ionic

i want to add toast message on click of a button:

I tried this but getting error on show method:

It says:

message: 'Property ‘show’ does not exist on type ‘Toast’.

this.toast.show(‘Im a toast’, ‘5000’, ‘center’).subscribe( toast => { console.log(toast);

I have used Import and added it in constructor also as described in the docs:

import { Toast } from ‘@ionic-native/toast’;

constructor(private toast: Toast) { }

this.toast.show(‘I’m a toast’, ‘5000’, ‘center’).subscribe(
toast => {
console.log(toast);
}
);

How should I do this…
Thanks in Advance.

Use this function:

presentToast() {
    let toast = this.toastCtrl.create({
      message: 'Toast Message',
      duration: 3000
    });
    toast.present();
  }
2 Likes

I tried this also but getting error
create and present does not exist

You need to import Toast Controller by using this code:

import { ToastController } from 'ionic-angular';

Then you will need to add this in controller:

public toastCtrl: ToastController

Please refer to this link:

1 Like

Thanks a lot it worked…

like this error getting
Unexpected value ‘ToastController’ imported by the module ‘AppModule’. Please add a @NgModule annotation.