Angular PrimeNG表单密码定制组件
Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,这个框架用于制作响应式网站,非常容易。在这篇文章中,我们将学习如何在Angular PrimeNG中使用Form密码定制组件。
密码组件是用来表示密码字段的强度指标的。对于中、强密码,密码组件采用正则表达式,设置如下。
语法:
<p-password placeholder="Password" strongRegex>
<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表单密码定制属性:
- mediumRegex:它是用于密码检查的中级正则表达式。它是字符串数据类型,默认值是中级密码的正则表达式。
- strongRegex:它是用于密码检查的中级正则表达式。它是字符串数据类型,默认值是强级密码的重码。
- placeholder。它用于设置输入的占位符文本。它是字符串数据类型,默认值为空。
Angular PrimeNG表格密码定制模板:
- header。它是该元素的标题部分。
- content。它是元素的内容部分。
- footer。它是该元素的页脚部分。
创建Angular应用程序和模块安装。
第1步:使用以下命令创建一个Angular应用程序。
ng new appname
第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
第3步:在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
项目结构:它将看起来像如下。
运行应用程序的步骤:运行以下命令以查看输出结果
ng serve --open
示例1:下面是说明使用Angular PrimeNG Form Password Customization Component的示例代码。
- app.component.html:
<h1 style="color: green">GeeksforGeeks</h1>
<h5>
Angular PrimeNG Form Password
Customization 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:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {}
- 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';
import { DividerModule } from 'primeng/divider';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
PasswordModule,
DividerModule,
FormsModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule
输出:
示例2:下面是另一个示例代码,说明了Angular PrimeNG Form Password Customization Component使用一些不同的属性值。
- app.component.html:
<h1 style="color: green">GeeksforGeeks</h1>
<h5>
Angular PrimeNG Form Password
Customization Component
</h5>
<p-password placeholder="Password" class="p-inputtext-lg"
strongRegex [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:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {}
- 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';
import { DividerModule } from 'primeng/divider';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
PasswordModule,
DividerModule,
FormsModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule
输出: