Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Angular PrimeNG Password Component

  • Last Updated : 24 Aug, 2021

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 know how to use the Password component in Angular PrimeNG.

Password Component: It is used to represent the strength indicator for the password fields. 

Properties:

  • promptLabel: It is used to show some text to prompt password entry. It is of string data type, the default value is null.
  • mediumRegex: It is the medium regular expression to be used for password checking. It is of string data type, the default value is the regex for a medium-level password.
  • strongRegex: It is the medium Regular expression to be used for password checking. It is of string data type, the default value is the regex for a strong level password.
  • weakLabel: It is used to show text for a weak password entry. It is of string data type, the default value is null.
  • mediumLabel: It is used to show text for a medium password entry. It is of string data type, the default value is null.
  • strongLabel: It is used to show text for a strong password entry. It is of string data type, the default value is null.
  • feedback:  It is used to show the strength indicator or not. It is of the boolean datatype, the default value is true.
  • toggleMask: It is used to show an icon to display the password as plain text. It is of the boolean datatype, the default value is false.
  • appendTo: This property takes the ID of the element on which overlay is appended to. It is of string data type, the default value is null.
  • inputStyle: It is used to set the Inline style of the input field. It is of string data type, the default value is null.
  • inputStyleClass: It is used to set the Style class of the input field. It is of string data type, the default value is null.
  • inputId: It is an ID identifier of the underlying input element. It is of string data type, the default value is null.
  • style: It is used to set the Inline style of the element. It is of string data type, the default value is null.
  • styleClass: It is used to set the Style class of the element. It is of string data type, the default value is null.
  • placeholder: It is used to set the Placeholder text for the input. It is of string data type, the default value is null.

Templates:

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

 



Styling:

  • p-password-panel: It is a styling Container of password panel.
  • p-password-meter: It is a styling Meter element of password strength.
  • p-password-info: It is a Text to display strength.

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.

 



Example 1: This is the basic example that shows how to use the Password component. 

app.component.html




<h2>GeeksforGeeks</h2>
<h5>PrimeNG Password Component</h5>
<p-password [feedback]="false"></p-password>
<p-password [disabled]="true" [feedback]="false"></p-password>

app.module.ts




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";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    PasswordModule,
    FormsModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

Output:

Example 2: In this example, we will know how to use the toggleMask property in the password component. 

app.component.html




<h2>GeeksforGeeks</h2>
<h5>PrimeNG password component</h5>
<p-password [toggleMask] ="true"></p-password>

app.module.ts




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";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    PasswordModule,
    FormsModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

Output:

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :