Angular PrimeNG Messages Static Content
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 the static content in Messages Component in Angular PrimeNG.
The Messages component is used to display a message with particular severity. To display the static content, the user can make use of the message template. Message service is ignored and no need to assign any value.
Syntax:
<p-messages severity="info"> <ng-template pTemplate> ... </ng-template> </p-messages>
Creating Angular application & Module Installation:
Step 1: To create an angular app, you need to install the angular command line interface through the npm command:
npm install -g angular-cli
Step 2: Now, we will create an angular project:
ng new project_name
Step 3: After creating your angular project, move into the folder to perform different operations:
cd project_name
Step 4: After creating the Angular application, Install the required module using the following command:
npm install primeng --save npm install primeicons --save
Project Structure: After successful installation, the following project structure will appear:
- Step to Run Application: Run the application using the following command from the root directory of the project:
ng serve --open
Example 1: This example describes the Angular PrimeNG Messages Static Content.
- app.component.html
HTML
< div style = "margin:100px;" > < h1 style = "color: green" >w3wiki</ h1 > < h3 >Angular PrimeNG Messages Static Content</ h3 > < p-messages severity = "success" > < ng-template pTemplate> < img src = 'https://media.w3wiki.net/wp-content/uploads/20210604014825/QNHrwL2q-100x100.jpg' width = "32" /> < div class = "ml-2" >Beginner For Beginner</ div > </ ng-template > </ p-messages > </ div > |
- app.component.ts
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'my-app' , templateUrl: './app.component.html' , }) export class AppComponent { } |
- 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 { ToastModule } from 'primeng/toast' ; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, MessagesModule, ToastModule, BrowserAnimationsModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } |
Output:
Example 2: This example describes the Angular PrimeNG Messages Static Content.
- app.component.html
Javascript
<div style= "margin:100px;" > <h1 style= "color: green" >w3wiki</h1> <h3>Angular PrimeNG Messages Static Content</h3> <p-messages severity= "error" > <ng-template pTemplate> <i class= "pi pi-times-circle pi-spin" ></i> <div class= "ml-2" >Error occurred</div> </ng-template> </p-messages> <p-messages severity= "info" > <ng-template pTemplate> <div class= "ml-2" >Information received</div> <i class= "pi pi-info-circle pi-spin" ></i> </ng-template> </p-messages> <p-messages severity= "warn" > <ng-template pTemplate> <i class= "pi pi-exclamation-triangle pi-spin" ></i> <div class= "ml-2" >Alert message</div> </ng-template> </p-messages> </div> |
- app.component.ts
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'my-app' , templateUrl: './app.component.html' , }) export class AppComponent { } |
- 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 { ToastModule } from 'primeng/toast' ; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, MessagesModule, ToastModule, BrowserAnimationsModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } |
Output:
Reference: https://primefaces.org/primeng/messages