Skip to content
the poor coder

add toaster in angular

Poor Man
Published
Reading time
1 min read

Adding a toaster in Angular is easy and can be done in a few steps. First, install the angular-toastr library using npm or yarn, depending on your preference. To install with npm, run the following command in your terminal:

Text
npm install angular-toastr --save

To install with yarn, run the following command in your terminal:

Text
yarn add angular-toastr

Next, you need to add the library to the list of modules in your app.module.ts file. You can do this by adding the following line to the NgModule section of the file:

Text
import { ToastrModule } from 'angular-toastr';

Then, add the ToastrModule to the imports array of the @NgModule like this:

Text
imports:[
  ToastrModule.forRoot(),
]

Now that the library is installed and imported, you can use the toaster service in your components. To use the service, first you need to inject it into your component class. Then you can call the toastr methods to show different messages. Here is an example of how you could use the service to show a success message:

Text
import { ToastrService } from 'angular-toastr';

export class AppComponent {
  constructor(public toastr: ToastrService) {}
  
  showSuccess() {
    this.toastr.success('This is a success message', 'Success!');
  }
}

Now you can call the showSuccess() method in your component to show the success message. You can check the library documentation for more information about all the available methods and options. That's it - you now have a toaster in your Angular application.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC