Open In App

Angular PrimeNG Messages Closable

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will see how to use the Messages Closable in Angular PrimeNG. We will also learn about the properties with their syntaxes that will be used in the code.

The Messages component is used to display a message with particular severity. Since messages can be closed by default, a close symbol is visible in the upper right corner. Using the [closable]=”false” attribute, we can make the closable icon inactive.



Syntax:

<p-messages 
        [closable]="false" 
        [(value)]="...">
</p-messages>

Angular PrimeNG Messages Closable properties:



Creating Angular application & module installation:

Step 1: Create an Angular application using the following command.

ng new appname

Step 2: After creating your project folder i.e. appname, move to it using the following command.

cd appname

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: It will look like the following:

 

ng serve --open

Example 1: Below is the example code that illustrates the use of Angular PrimeNG Messages Closable.




<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG Message Closable</h5>
  
    <p-messages
          [closable]="false"
          [(value)]="gfg"> 
    </p-messages>
</div>




import { Component } from "@angular/core";
import { Message } from "primeng/api";
  
@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
})
export class AppComponent {
  gfg: Message[];
  
  ngOnInit() {
    this.gfg = [
      {
        severity: "success",
        summary: "Geek-Success",
        detail: "This is a success Geek",
      },
      {
        severity: "info",
        summary: "Geek-Info",
        detail: "This is a info Geek",
      },
    ];
  }
}




import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import {MessagesModule} from 'primeng/messages';
  
@NgModule({
  imports: [
    BrowserAnimationsModule,
    MessagesModule,
  ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule{}

Output:

 

Example 2: Below is another example that illustrates the Angular PrimeNG Messages Closable, by specifying the [closable] attribute as true.




<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG Message Closable</h5>
  
    <p-messages
          [closable]="true"
          [(value)]="gfg"> 
    </p-messages>
</div>




import { Component } from "@angular/core";
import { Message } from "primeng/api";
  
@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
})
export class AppComponent {
  gfg: Message[];
  
  ngOnInit() {
    this.gfg = [
      {
        severity: "warn",
        summary: "Geek-Warn",
        detail: "This is a warn Geek",
      },
      {
        severity: "error",
        summary: "Geek-Error",
        detail: "This is a error Geek",
      },
    ];
  }
}




import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import {MessagesModule} from 'primeng/messages';
  
@NgModule({
  imports: [
    BrowserAnimationsModule,
    MessagesModule,
  ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
  
export class AppModule {}

Output:

 

Reference: https://primefaces.org/primeng/messages


Article Tags :