Angular PrimeNG Messages Templates
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 learn about Angular PrimeNG Messages Templates
The messages component is used to display the message with particular severity.
Angular PrimeNG Messages Templates: The templates are used to put some content on some pre-structured containers. Message templates are discussed below
- content: This is used to place the content of the Message Component
Syntax:
<p-messages [(value)]="..."> </p-messages>
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:
Steps to run the application: Run the below command to see the output.
ng serve --save
Example 1: In this example, we will learn about Message Templates.
- app.component.html:
HTML
< div style = "width:50%" > < h1 style = "color:green" >w3wiki</ h1 > < h2 >Angular PrimeNG Messages Templates </ h2 > < p-messages [(value)]="gfg" [enableService]="false" [closable]="false"> </ p-messages > </ div > |
- app.component.ts:
Javascript
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 Message Template" , }, ]; } } |
- app.module.ts:
Javascript
import { NgModule } from "@angular/core" ; import { BrowserModule } from "@angular/platform-browser" ; import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ; import { AppComponent } from "./app.component" ; import { MessagesModule } from "primeng/messages" ; import { MessageModule } from "primeng/message" ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, MessagesModule, MessageModule, ], declarations: [AppComponent], bootstrap: [AppComponent], }) export class AppModule {} |
Output:
Example 2: In this example, we will learn about Multiple Message severities templates and closable message templates.
- app.component.html:
HTML
< div style = "width:50%" > < h1 style = "color:green" >w3wiki</ h1 > < h2 >Angular PrimeNG Messages Templates </ h2 > < p-messages [(value)]="gfg" [enableService]="false" > </ p-messages > </ div > |
- app.component.ts:
Javascript
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 Message Template" , }, { severity: "warn" , summary: "Geek-Warning" , detail: "This is a warning Message Template" , }, { severity: "error" , summary: "Geek-Error" , detail: "This is a error Message Template" , }, ]; } } |
- app.module.ts:
Javascript
import { NgModule } from "@angular/core" ; import { BrowserModule } from "@angular/platform-browser" ; import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ; import { AppComponent } from "./app.component" ; import { MessagesModule } from "primeng/messages" ; import { MessageModule } from "primeng/message" ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, MessagesModule, MessageModule, ], declarations: [AppComponent], bootstrap: [AppComponent], }) export class AppModule {} |
Output:
Reference: https://primefaces.org/primeng/messages
Contact Us