Open In App

Angular PrimeNG Form Password Styling Component

Angular PrimeNG is an open-source front-end UI framework developed by PrimeTek for developing efficient and scalable angular applications. Using PrimeNG in their projects helps developers to cut down the development time and focus on other important areas of the application. In this article, we will be seeing the Angular PrimeNG Form Password Styling 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. There are 3 structural styling classes of the password component which can be used to style the component.



Angular PrimeNG Form Password Styling Classes:

 



Angular PrimeNG Form Password Styling Properties:

Syntax:

// In app.component.html
<p-password 
    [(ngModel)]="..." 
    placeholder="...">
</p-password>

// In app.component.css
:host ::ng-deep .Password-Styling-Class{
    // CSS
}

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 shows the use of the “p-password-panel” class to change the styling of the password component panel.




<h2 style="color: green">GeeksforGeeks</h2>
<h3>
    Angular PrimeNG Form
    Password Styling Component
</h3>
  
<p-password [(ngModel)]="password" 
            placeholder="Enter the Password">
</p-password>




:host ::ng-deep .p-password-panel {
    color: green;
    border: 2px solid green;
    background: #ffcccc;
}




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
})
  
export class AppComponent {
    password?: 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:

 

Example 2: In this example, we used the above-mentioned styling class to change the height and the border radius of the password strength meter and change the color and font weight of the text.




<h2 style="color: green">GeeksforGeeks</h2>
<h3>
    Angular PrimeNG Form
    Password Styling Component
</h3>
  
<p>Default Password Component</p>
<p-password [(ngModel)]="password" 
            placeholder="Enter the Password">
</p-password>
  
<p class="mt-6">
      Custom Styled Password Component
</p>
<p-password class="myPass"
              [(ngModel)]="myPassword" 
              placeholder="Enter the Password">
</p-password>




:host ::ng-deep .myPass .p-password-meter {
    border: 1px solid red;
    height: 15px;
    border-radius: 10px;
}
  
:host ::ng-deep .myPass .p-password-panel {
    color: green;
    font-weight: bold;
    font-size: 20px;
}




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
})
  
export class AppComponent {
    password?: string;
    myPassword?: 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 :