我正试图使用素数12来限制输入中的字符数,maxlength属性似乎不适用于此密码组件,在正常输入中工作正常,但我需要特殊功能,如密码强度模板,我能做什么?
<p-password [style]="{'width':'100%'}" [pKeyFilter]="blockSpace" [inputStyle]="{'width':'100%'}" placeholder="Contraseña" formControlName="password" maxlength='16' [feedback]="false"></p-password>
在常规输入中,最大长度可防止键入超过16个字符,但使用p密码时,用户不能键入无限字符
真的很晚才回答,但问题仍然存在于素数13上。下面是我为添加功能而实现的解决方案。我在使用指令。希望它能帮助
import {
AfterContentChecked,
Directive,
ElementRef,
Input
} from '@angular/core';
@Directive({
selector: '[compPasswordMaxLength]',
})
export class CompPasswordMaxLengthDirective
implements AfterContentChecked {
@Input('compPasswordMaxLength') length: number;
private domElement: HTMLElement;
constructor( private elementRef: ElementRef) {
// get ref HTML element
this.domElement = this.elementRef.nativeElement as HTMLElement;
}
public ngAfterContentChecked(): void {
const input = this.domElement.getElementsByTagName('input');
if (input && input.length > 0) {
(input[0] as HTMLElement).setAttribute('maxlength', this.length.toString());
}
}
}
用法:
<p-password formControlName="password" [compPasswordMaxLength]="maxLength_Password">
</p-password>