Open In App

Angular PrimeNG Form Password Properties Component

Angular PrimeNG is an open-source front-end UI library that has many native Angular UI components which help developers to build a fast and scalable web solution. This article will discuss the Angular PrimeNG Form Password Properties Component.

The Password Component is used to take the input of sensitive information like passwords, credit/debit card CVV, etc from the user. When it is in focus a password strength indicator is shown to the user. All the properties of the Password component are listed below.



Angular PrimeNG Form Password Properties:

 



Syntax:

<p-password
    placeholder="..."
    [showClear]="..."
    [toggleMask]="..."
    promptLabel="..."
    weakLabel="..."
    mediumLabel="..."
    strongLabel="..."
    [inputStyle]="..."
    ...
    [(ngModel)]="...">
</p-password>

Creating Angular Application and Installing the Module:

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: Finally, Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: The project Structure will look like this after following the above steps:

Project Structure

Example 1: This example illustrates the use of the promptLabel, weakLabel, mediumLabel, and strongLabel properties to customize the label of the password accordingly.




<h2 style="color: green;">GeeksforGeeks</h2>
<h3>
    Angular PrimeNG Form
    Password Properties Component
</h3>
  
<h4>Default Password Component</h4>
<p-password placeholder="Enter the password"
            promptLabel="Choose a password"
            weakLabel="The password is weak"
            mediumLabel="The password is medium"
            strongLabel="The password is strong"
            [(ngModel)]="password1">
</p-password>




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
})
  
export class AppComponent {
    password1?: string;
}




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

Output:

 

Example 2: This example used the showClear, placeholder, inputStyle, and toggleMask properties of the password component to render the show/hide password icon, change input style, show a clear icon button, etc.




<h2 style="color: green;">GeeksforGeeks</h2>
<h3>
    Angular PrimeNG Form
    Password Properties Component
</h3>
  
<p-password placeholder="Enter the password"
            [showClear]="true"
            [toggleMask]="true"
            [inputStyle]="{'border-color': 'green'}"
            [(ngModel)]="password1">
</p-password>




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
})
  
export class AppComponent {
    password1?: string;
}




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

Output:

 

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


Article Tags :