Ionic 4 + Angular 9
Creation of Toast Controller Common Class
Create Toast Common Class
Create a class which takes Toast Controller instance as constructor parameter
export class ToastNotification {
constructor(private toast){}
async openToast(message,duration,position){
const toast = await this.toast.create({
message:message,
duration:duration,
position:position
});
toast.present();
}
}
Create Instance of the ToastNotification Class and use the object to access OpenToast Function
import {ToastNotification} from '../../_helpers/toastnotification';
import { ToastController} from '@ionic/angular';
export class example {
constructor(private toast:ToastController){}
toastpop = new ToastNotification(this.toast);
this.toastpop.openToast("Hello World",2000,top);
}