Angular PrimeNG Form Password Model Binding
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.
The Password Component is used to represent the strength indicator for the password fields.
Model Binding: The ngModel directive is used to bind the model with the password component.
Â
Syntax:
<p-password
[(ngModel)]="....">
</p-password>
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.
Â
Step to run the application: Run the below command to see the output
ng serve --save
Example 1: In the below code we will make use of the above syntax to demonstrate the use of the Form Password Model Binding Component.
HTML
< div style = "text-align:center" >
< h1 style = "color:green" >GeeksforGeeks</ h1 >
< h3 >Angular PrimeNG Form Password
Model Binding Component</ h3 >
< p-password [(ngModel)]="value1"></ p-password >
</ div >
|
Javascript
import { Component } from "@angular/core" ;
@Component({
selector: "app-root" ,
templateUrl: "./app.component.html" ,
styles: [
`
:host ::ng-deep .p-password input {
width: 15rem;
}
`
]
})
export class AppComponent {
value1: string;
value2: string;
value3: string;
value4: string;
}
|
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: In the below code we will make use of the above syntax to demonstrate the use of the Form Password Model Binding Component.
HTML
< div style = "text-align:center" >
< h1 style = "color:green" >GeeksforGeeks</ h1 >
< h3 >
Angular PrimeNG Form Password
Model Binding Component
</ h3 >
< p-password
[(ngModel)]="value1"
[toggleMask]="true">
</ p-password >
</ div >
|
Javascript
import { Component } from "@angular/core" ;
@Component({
selector: "app-root" ,
templateUrl: "./app.component.html" ,
styles: [
`
:host ::ng-deep .p-password input {
width: 15rem;
}
`
]
})
export class AppComponent {
value1: string;
value2: string;
value3: string;
value4: string;
}
|
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 :
05 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...