Open In App

Angular PrimeNG Form Password Templating 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 Form Password Templating Component in Angular PrimeNG.

The Password Component is used to represent the strength indicator for the password fields. The overlay may be customized using 3 supplied templates. The header, content, and footer are these. Note that the default meter is superseded by content.

Syntax:

<p-password>
     <ng-template pTemplate="header">
         <h6>...</h6>
     </ng-template>
     
     <ng-template pTemplate="footer">
         <p-divider></p-divider>
         <p class="...">....</p>
         <ul class="..." style="...">
             <li>...</li>
             ...
         </ul>
     </ng-template>
</p-password>

 

Angular PrimeNG Form Password Show Password properties:

  • feedback:  It is used to show the strength indicator or not. It is of the boolean datatype, and the default value is true.
  • placeholder: It is used to set the Placeholder text for the input. It is of string data type, the default value is null.

Angular PrimeNG Form Password Show Password Templates:

  • header: It is the header part for the element.
  • content: It is the content part of the element.
  • footer: It is the footer part for the element.

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.

 

Steps to run the application: Run the below command to see the output

ng serve --open

Example 1: Below is the example code that illustrates the use of the Angular PrimeNG Form Password Templating Component.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>
    Angular PrimeNG Form Password 
      Templating Component
</h5>
  
<p-password placeholder="Password" 
    class="p-inputtext-sm">
    <ng-template pTemplate="header">
        <h6>Pick a password</h6>
    </ng-template>
  
    <ng-template pTemplate="footer">
        <p-divider></p-divider>
        <p class="p-mt-2">Hints:</p>
        <ul class="p-pl-2 p-ml-2 p-mt-0" 
            style="line-height: 1.6">
            <li>Enter atleast 1 lowercase character</li>
            <li>Enter atleast 1 uppercase character</li>
            <li>Enter atleast 1 numeric character</li>
            <li>Enter minimum 8 characters</li>
        </ul>
    </ng-template>
</p-password>


  • 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 { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { PasswordModule } from 'primeng/password';
import { DividerModule } from 'primeng/divider';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        PasswordModule,
        DividerModule,
        FormsModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
  
export class AppModule {}


Output:

 

Example 2: Below is another example that illustrates the use of Angular PrimeNG Form Password Templating Component using some different property values.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>
    Angular PrimeNG Form Password 
      Templating Component
</h5>
  
<p-password placeholder="Password" 
    class="p-inputtext-lg" [toggleMask]="true">
    <ng-template pTemplate="header">
        <h6>Pick a password</h6>
    </ng-template>
  
    <ng-template pTemplate="footer">
        <p-divider></p-divider>
        <p class="p-mt-2">Hints:</p>
        <ul class="p-pl-2 p-ml-2 p-mt-0" 
            style="line-height: 1.4">
            <li>Enter atleast 1 lowercase character</li>
            <li>Enter atleast 1 uppercase character</li>
            <li>Enter atleast 1 numeric character</li>
            <li>Enter minimum 8 characters</li>
        </ul>
    </ng-template>
</p-password>


  • 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 { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } 
   from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { PasswordModule } from 'primeng/password';
import { DividerModule } from 'primeng/divider';
  
@NgModule({
   imports: [
       BrowserModule,
       BrowserAnimationsModule,
       PasswordModule,
       DividerModule,
       FormsModule,
   ],
   declarations: [AppComponent],
   bootstrap: [AppComponent],
})
  
export class AppModule {}


Output:

 

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



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