How to display ngx-toastr using the show() method in Angular 2+ with a specific type

Working with

ToastrService.success/error/warning/info()
poses no issues for me,

However, when attempting to utilize ToastrService.show(), I am unsure of the correct string type to pass along

I made an attempt by sending an enum like so:

export enum ToastType {
    Success = 'success',
    Error = 'error',
    Info = 'info',
    Warning = 'warning'
}

Unfortunately, this caused the component to lose its styles.

Answer №1

Encountered the same issue and came across the defined types in the documentation:

iconClasses = {
  error: 'toast-error',
  info: 'toast-info',
  success: 'toast-success',
  warning: 'toast-warning'
};

Source: https://github.com/scttcper/ngx-toastr#iconclasses-defaults

UPDATE

The show() method requires four parameters, with the types mentioned above.

ToastrService.show(message?: string, title?: string, override?: Partial<IndividualConfig>, type?: string)

An example showcasing all parameters can be found here: https://stackblitz.com/edit/angular-uu7r6s

For a more comprehensive example, check out: https://github.com/grabowskidaniel/exemplo-ngx-toastr

Utilizing NgxToastr version 10

Answer №2

My implementation of ToasterService involves the following code snippets:

this._toasterService.openToast("", "Data updated successfully!", "success");

this._toasterService.openToast("", "Error updating data!", "error");

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

Exceljs : 'An issue has been identified with certain content in the document named "file.xlsx"(...)'

I have encountered an issue with an xlsx file generated using Exceljs. While I have been creating csv files in my project without any problems, creating an xlsx file now poses an error. The xlsx file opens clean on Ubuntu/LibreOffice Calc, but there is an ...

I require the ability to modify cellEditor parameters in real-time

How can a value be passed to cellEditorParams after the user double clicks on a grid row? The application triggers a service call on row click and the response needs to be sent to cellEditorParams. ...

What exactly does the use of type assertion as any in Typescript entail?

I'm attempting to dissect a portion of code and figure out its functionality. While I've encountered type assertion before, this particular example is proving to be quite baffling for me. (this.whatever as any).something([]); Here's the la ...

Animating the Click Event to Change Grid Layout in React

Can a grid layout change be animated on click in React? For instance, consider the following component: import { Box, Button, styled, useMediaQuery } from "@mui/material"; import Row1 from "./Row1"; import React from "react"; ...

TypeScript's robustly-typed rest parameters

Is there a way to properly define dynamic strongly typed rest parameters using TypeScript 3.2? Let's consider the following scenario: function execute<T, Params extends ICommandParametersMapping, Command extends keyof Params, Args extends Params[C ...

What is the best way to first identify and listen for changes in a form

In Angular, there are reactive forms that allow you to track changes in both the complete form and specific fields: this.filterForm.valueChanges.subscribe(() => { }); this.filterForm.controls["name"].valueChanges.subscribe(selectedValue => { }); ...

Having trouble linking a nested form group to a form array in reactive Forms?

https://example.com Unable to connect {form control} with data [ { "group1": "", "group2": { "data": "" } } ] Require binding using form control name <form [formGroup]="formGroup"> <div f ...

Detecting the State of the Keyboard in Ionic 2

Seeking an easy way to determine if the mobile device keyboard has been opened or closed using Ionic2 and Angular2. Is there a 'keyboard-open' or 'keyboard-close' class that Ionic sends to the body/html? ...

Creating an HTML tag from Angular using TypeScript

Looking at the Angular TypeScript code below, I am trying to reference the divisions mentioned in the HTML code posted below using document.getElementById. However, the log statement results in null. Could you please advise on the correct way to reference ...

Blending i18n JIT and AOT in Angular 6

Currently, it appears that the development environment is utilizing Just-In-Time (JIT) compilation while production is using Ahead-Of-Time (AOT) compilation, which is expected behavior. However, an issue arises when attempting to retrieve the LOCALE_ID in ...

Is it possible to export multiple services in an Angular custom library?

After developing a customized library named test-lib, I am able to export TestLibService, TestLibModule, and TestLibComponent using public-api.ts. This allows me to utilize TestLibService from the custom library within an Angular App. The app.module.ts fi ...

Changing the Size of a Map using react-simple-maps within a React Application

I'm having difficulties with displaying a France map using react-simple-maps. The issue I'm facing is that the map appears too small despite my efforts to adjust it through CSS, width and height attributes, and by utilizing ZoomableGroup. Unfortu ...

Since transitioning my project from Angular 7.2 to Angular 8, I noticed a significant threefold increase in compile time. How can I go about resolving this issue

After upgrading my project to Angular 8, I noticed a significant increase in compile time without encountering any errors during the upgrade process. Is there a way to restore the previous compile time efficiency? **Update: A bug has been identified as th ...

Mastering Generic Types in Functions in Typescript

My current structure looks like this: export interface Complex { getId<T>(entity: T): string } const test: Complex = { getId<Number>(entity){return "1"} // encountering an error 'entity is implicitly any' } I am wondering w ...

Leverage images within the Angular library

I am currently working on creating an Angular library that includes a component with an image. I have successfully added the image as an asset in the library, but when trying to display it, the image doesn't show up. Here is the current folder structu ...

How does the order of objects in an array change when using *ngFor in Angular with a .subscribe() method in Ionic 3?

As a newcomer to Ionic 3 & Angular, I encountered a challenge with the *ngFor and .subscribe() method. Please bear with me if this question seems simple. I attempted to understand the behavior of the http.get(..).map(..).subscribe() function when combined ...

Tips for calculating the total count of a specific field within a JSON array with TypeScript

I have a JSON array. "user": { "value": [ { "customerNo": "1234" }, { "customerNo": "abcd" }, { "c ...

Encountering an "ionic 4 frame-ancestors *" error while attempting to watch a Twitter video

Currently, I am in the process of developing a news app using Ionic 4. I recently tackled the challenge of embedding tweets in Twitter cards successfully. However, a new issue has arisen. When a tweet includes a Youtube video, everything works perfectly ac ...

There was an issue attempting to differentiate '[object Object]'. The Angular API Get Request from .Net only allows for arrays and iterables to be used

I am currently in the learning stage and consider myself a novice, so please forgive me if this question seems silly. I am working on a Movie Database project that involves integrating movies from a live API, creating a favorite list, implementing JWT auth ...

Creating a shadow effect on a mat-card component in Angular

Working on my project that involves an angular frontend, I attempted to add a shadow effect to one of my components by using class="mat-elevation-z8". Strangely, this did not have the desired effect. This is the HTML code in question: <mat-card class= ...