numerous slices of toasted bread for the latest version of Ionic

I'm looking to implement multiple toasts in Ionic framework v4, but I'm not sure how to go about coding it.

I attempted to implement multiple toasts in Ionic v3, but it didn't meet my requirements.

import { Component, OnInit } from '@angular/core';
import { ToastController } from '@ionic/angular';

@Component({
  selector: 'gd-toast',
  templateUrl: './gd-toast.component.html',
  styleUrls: ['./gd-toast.component.scss'],
})

export class GdToastComponent implements OnInit {

  constructor(public toastController: ToastController){}
  ngOnInit() {
  }

  public toastMsgs: any = [];

  async presentToast(msg) {
      this.toastMsgs.push(msg);
      const toast = await this.toastController.create({
          message: this.toastMsgs.toString().split(",").join("\n"),
          position: 'bottom',
          showCloseButton: true,
          closeButtonText: 'Ok',
          // duration: 3000,       
      });
      toast.present();
      toast.onDidDismiss().then(() => {
          this.toastMsgs = [];
      });
  }

}

Answer №1

Give this method a shot

displayToastMessage(message) {
    this.mytoastController.create({
      message: 'Your message is: ' + message,
      duration: 2000,
      animated: true,
      showCloseButton: true,
      closeButtonText: "Done",
      cssClass: "my-toast",
      position: "middle"
    }).then((toast) => {
      toast.present();
    });
  }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the proper way to employ if and else if statements within Angular2?

Here's a question that has been duplicated on my How to utilize *ngIf else in Angular? post! ...

Creating a series of text messages for Push Notifications using FCM in conjunction with Ionic 1. Multiple lines of

I've been attempting to send push notifications with multiline text messages. I've experimented with various techniques such as using setBigStyle in FCMService.java, HTML.fromHTML, and others, but haven't been successful in getting the messa ...

Problems arising from the layout of the PrimeNG DataView component when used alongside Prime

I've been working with a PrimeNG DataView component that requires the use of PrimeFlex's flex grid CSS classes to set up the grid structure. One of their examples includes the following instructions: When in grid mode, the ng-template element ...

What criteria does Angular use to determine when the aot compiler should be utilized?

This page discusses the concept of modules in Angular and explains the two approaches to bootstrapping - dynamic and static. The configuration for these approaches is typically found in main.ts: // Using the browser platform with a compiler import { platf ...

What are the steps to create observable data from asynchronous sources?

Recent adopter of observables. I am utilizing ssh2 to retrieve a directory listing from my server. However, I am struggling to convert the data into an observable format since most online examples involve using http instead of an external module. Any sugg ...

Isolated Modules in Angular Version 17 and Beyond

Having worked with an earlier version of Angular, I am facing issues with my navbar routes not working properly on my Contact Page. Can someone shed some light on this for me? If you want to take a look at the code, here is the link: https://github.com/Lo ...

Encountering "Invalid hook call" error with React Router while integrating Higher Order Components for authentication

Dealing with an error: React Router shows "Invalid hook call" with higher-order components for authentication Dilemma I have developed two distinct approaches for authentication wrappers in my React components with React Router. The first method functions ...

Include a class in ul > li elements upon page load in Angular4

I attempted to add a class to each "li" element in an Angular4 page, but the class was not applied. Here is the relevant HTML code: <ul class="pagination"> <button class="previous" (click)="previous()">Previous</button> <button ...

"Encountering a problem with the debounceTime operator in rxjs and HTTP requests while using the keyup

I have been working on implementing server-side search in Angular 7. I managed to find some code for implementation, but unfortunately it is not functioning as expected. The issue I am encountering is that when searching for a string, the code sends mult ...

Experiencing difficulty accessing the response header in Angular 16 due to CORS restrictions

When attempting to retrieve the response header from my post call, I am encountering difficulties as it appears there are "no headers" or I may be doing something incorrectly. On the backend, I am utilizing ASP.NET Core. Below is a basic outline of my API ...

Expanding containers with flexbox to allow for flexibility in size

I need help with a page that contains 3 div elements, where 2 of them need to be resizable. These elements should be able to be moved left or right, and maximized or minimized. You can view the example on Stackblitz. The issue I'm facing is that som ...

Disabling `no-dupe-keys` in ESLint does not seem to be effective

Currently, I am working on a project where I have incorporated Typescript and ESLint. However, I have encountered an issue with the error message stating: An object literal cannot have multiple properties with the same name. I am looking to disable this s ...

React Native is throwing a TypeError because it is encountering an undefined object

React Native is throwing an error claiming Undefined is not an object when it's clearly an object!! I'm confused about what's happening. Take a look at the code snippet below. Scroll down to the render() function. You'll see the follow ...

Avoiding data type conversion in JavaScript/TypeScript

Currently delving into the world of JavaScript, I come from a background of working with statically typed languages. Naturally, I opted to dive into TypeScript instead of starting directly with JS. While TypeScript is great and addresses many issues presen ...

Angular 4's Mddialog experiencing intermittent display problem

While using MDDialog in my Angular app, I've encountered a couple of issues. Whenever a user clicks on the div, flickering occurs. Additionally, if the user then clicks on one of the buttons, the afterclose event is not triggered. Can anyone provide ...

Troubleshooting: Facing the "jspdf__WEBPACK_IMPORTED_MODULE_2__.jsPDF is not a constructor" error while trying to utilize jsPDF in Angular 7?

I'm currently facing an issue with integrating jsPDF into my Angular 7.1.3 project. Here are the relevant sections from my package.json file: "dependencies": { "@angular/animations": "~7.1.0", "@angular/common": "~7.1.0", "@angular/compi ...

Is it necessary to create a unit test for a basic operation involving RxJS?

Imagine a straightforward class that triggers a new event to an RxJS subject whenever the window is resized. Disregard any perceived complexities, as the main point is that this class generates an event. export class ResizeService { priv ...

What could be causing the elements in my array to appear as undefined?

https://i.stack.imgur.com/ze1tx.png I'm stuck trying to understand why I can't extract data from the array. const usedPlatformLog: Date[] = [] users.forEach(el => { usedPlatformLog.push(el.lastUsed) }) console.log(usedPlatformLog) // disp ...

The event fails to propagate up to the parent component

I have a project structure set up as follows: https://i.stack.imgur.com/bvmK5.jpg The todo-form component triggers the created event and I am looking to handle this event in the todos component. todo-form.component.html: <form class="todo-form" ( ...

What is the process for server-side rendering an Angular application with Angular Universal and incorporating an SSL certificate?

Typically, when I want my angular applications to run locally over HTTPS, I install a certificate and make changes in the angular.json file like this: "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { " ...