Open In App

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:

Project Structure

ng serve --open

Example 1: This example describes the Angular PrimeNG Messages Static Content.




<div style="margin:100px;">
    <h1 style="color: green">GeeksforGeeks</h1>
    <h3>Angular PrimeNG Messages Static Content</h3>
    <p-messages severity="success">
        <ng-template pTemplate>
            <img src=
                 width="32" />
            <div class="ml-2">Geeks For Geeks</div>
        </ng-template>
    </p-messages>
</div>




import { Component } from '@angular/core';
 
@Component({
    selector: 'my-app',
    templateUrl: './app.component.html',
})
export class AppComponent { }




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.




<div style="margin:100px;">
    <h1 style="color: green">GeeksforGeeks</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>




import { Component } from '@angular/core';
 
@Component({
    selector: 'my-app',
    templateUrl: './app.component.html',
})
export class AppComponent { }




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


Article Tags :