Open In App

Angular PrimeNG Message Component

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:

Angular PrimeNG Message Component Styling:



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.




<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>




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




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.




<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>




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




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


Article Tags :