Open In App

Angular PrimeNG Message Component

Improve
Improve
Like Article
Like
Save
Share
Report

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 how to use the Message Component in Angular PrimeNG. We will also learn about the properties, along with their syntaxes that will be used in the code.

The Message Component is used to display a message with particular severity.

Angular PrimeNG Message Component Properties:

  • severity: It is used to specify the severity level of the message. It is of string data type, the default value is null.
  • text: It is used to set the text content. It is of string data type, the default value is null.
  • escape: Whether displaying messages would be escaped or not. boolean true
  • style: It is used to set the inline style of the component. It is of string data type, the default value is null.
  • styleClass: It is used to sets the style class of the component. It is of string data type, the default value is null.

Angular PrimeNG Message Component Styling:

  • p-inline-message: It is a message element.
  • p-inline-message-info: It is a message element when displaying info messages.
  • p-inline-message-warn: It is a message element when displaying warning messages.
  • p-inline-message-error: It is a message element when displaying error messages.
  • p-inline-message-success: It is a message element when displaying success messages.
  • p-inline-message-icon: It is used to specify the severity icon.
  • p-inline-message-text: It is a text message.

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: After complete installation, it will look like the following:

 

Steps to run the application: To run the above file run the below command:

ng serve --save

Example 1: This basic example shows how to use Angular PrimeNG Message Component.

  • app.component.html:

HTML




<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG Message Component</h5>
  
    <p-message severity="info"
        text="Info GeeksforGeeks"
        styleClass="p-mr-3">
    </p-message>
  
    <p-message severity="success"
        text="Success GeeksforGeeks"
        styleClass="p-mr-3">
    </p-message>
  
    <p-message severity="warn"
        text="Warn GeeksforGeeks"
        styleClass="p-mr-2">
    </p-message>
  
    <p-message severity="error"
        text="Error GeeksforGeeks"
        styleClass="p-mr-4">
    </p-message>
</div>


  • app.component.ts:

Javascript




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


  • app.module.ts:

Javascript




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


Output:

 

Example 2: This is another basic example that shows how to use Angular PrimeNG Message Component.

  • app.component.html:

HTML




<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG Message Component</h5>
      
    <div class="p-mt-4">
        <input
            type="email"
            pInputText
            placeholder="Email"
            class="ng-dirty
            ng-invalid p-mr-3">
        <p-message
            severity="error"
            text="Geek! This field is required">
        </p-message>
    </div>
  
    <div class="p-mt-4">
        <input
            type="password"
            pInputText
            placeholder="Password"
            class="ng-dirty
            ng-invalid p-mr-2">
  
        <p-message
            severity="error"
            text="Geek! Password in incorrect">
        </p-message>
    </div>
</div>


  • app.component.ts:

Javascript




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


  • app.module.ts:

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MessageModule } from 'primeng/message';
import { AppComponent } from './app.component';
import { InputTextModule } from 'primeng/inputtext';
  
@NgModule({
    imports: [
        BrowserModule,
        MessageModule,
        InputTextModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
  
export class AppModule {}


Output:

 

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



Last Updated : 02 Nov, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads