Wednesday, July 24, 2024

Angular 7 Flash Messages

Angular 7 Flash Messages

Hello to all, welcome to In this post, I will tell you, Angular 7 Flash Messages.

Angular 7 Has lots of new features and I will share this all. I have shown very simple example and everyone can understand this.


Here is the working image:

Angular 6 Flash Messages

 Angular provides us so many default features and Flash Message is one of them.

Here are the steps, you need to follow for Angular Flash Messages:


1. First, you need to run below command into your terminal to add Angular Flash Message Package into your Angular 7 App:
npm install angular2-flash-messages --save


2. After add below code into your app.module.ts file:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { FlashMessagesModule } from 'angular2-flash-messages';

  declarations: [AppComponent],
  imports: [
  entryComponents: [AppComponent],
  providers: [],
  bootstrap: [AppComponent]
export class AppModule { }


3. After this, you need to add below code into app.component.ts file:
import {Component} from '@angular/core';
import { FlashMessagesService } from 'angular2-flash-messages';
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
export class AppComponent {
constructor(private flashMessage: FlashMessagesService) { }
  showFlash() {
        // 1st parameter is a flash message text
        // 2nd parameter is optional. You can pass object with options.'Welcome To', { cssClass: 'alert-success', timeout: 2000 });


4. After it, you need to add below code into your app.component.html file:

On button click event, flash message will be shown:

<div class="jumbotron text-center">
  <h1>Angular Flash Messages
<button type="button" (click) = "showFlash()" class="btn btn-primary">Show Flash Messages</button>
<flash-messages></flash-messages><link href="" rel="stylesheet">

 Now you are done. If you have any query related to this post, then please ask questions or comment below.

Thank you,



the authortherichpost
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.