Open In App

Angular PrimeNG Messages Inline Message

Last Updated : 23 Aug, 2022
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 see how to use the Messages Inline Message 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. The Inline Message is generally displayed inline, mostly within the form.

Syntax:

 <p-message 
     severity="..." 
     text="..." 
     styleClass="...">
</p-message>

Angular PrimeNG Messages Inline Message properties:

  • styleClass: It sets the style class of the component. It is of string data type, the default value is null.
  • 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.

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:

 

  • Run the below command to see the output:
ng serve --open

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

app.component.html




<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG Inline Message</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-mt-3">
    </p-message>
  
    <p-message severity="error" 
               text="Error GeeksforGeeks" 
               styleClass="p-mr-4 p-mt-3">
    </p-message>
</div>


app.component.ts




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


app.module.ts




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: Below is another example that illustrates the Angular PrimeNG Messages Inline Message.

app.component.html




<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG Inline Message</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




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


app.module.ts




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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads