@@ -54,28 +54,31 @@ export class MatPasswordStrengthComponent implements OnInit, OnChanges {
5454 private _color : string ;
5555
5656 ngOnInit ( ) : void {
57- this . setRulesAndValidators ( ) ;
57+ setTimeout ( this . setRulesAndValidators ( ) , 100 ) ;
5858 }
5959
6060 ngOnChanges ( changes : SimpleChanges ) : void {
61- if ( changes . externalError && changes . externalError . firstChange ) {
62- this . _color = Colors . primary ;
61+ console . log ( '!changes.password.isFirstChange()' , changes . password . isFirstChange ( ) ) ;
62+ if ( ( changes . externalError && changes . externalError . firstChange ) || changes . password . isFirstChange ( ) ) {
63+ console . log ( 'ngOnChanges if' ) ;
6364 return ;
64- }
65- if ( changes . externalError && changes . externalError . currentValue ) {
65+ } else if ( changes . externalError && changes . externalError . currentValue ) {
66+ console . log ( 'ngOnChanges else if' ) ;
6667 this . _color = Colors . warn ;
6768 return ;
69+ } else {
70+ console . log ( 'ngOnChanges else' ) ;
71+ this . password && this . password . length > 0 ?
72+ this . calculatePasswordStrength ( ) : this . reset ( ) ;
6873 }
69- this . password && this . password . length > 0 ?
70- this . calculatePasswordStrength ( ) : this . reset ( ) ;
7174 }
7275
7376 get strength ( ) : number {
7477 return this . _strength ? this . _strength : 0 ;
7578 }
7679
7780 get color ( ) : string {
78-
81+ console . log ( 'on color requested: ' , this . strength ) ;
7982 if ( this . _strength <= 20 ) {
8083 return Colors . warn ;
8184 } else if ( this . _strength <= 80 ) {
@@ -139,8 +142,14 @@ export class MatPasswordStrengthComponent implements OnInit, OnChanges {
139142 this . criteriaMap . set ( Criteria . at_least_one_special_char , RegExp ( / ^ (? = .* ?[ " ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \] ^ _ ` { | } ~ " ] ) / ) ) ;
140143 }
141144
142- this . passwordFormControl = new FormControl ( '' ,
143- [ ...this . validators . map ( criteria => Validators . pattern ( this . criteriaMap . get ( criteria ) ) ) ] ) ;
145+ this . passwordFormControl . setValidators ( Validators . pattern ( this . criteriaMap . get ( Criteria . at_least_eight_chars ) ) ) ;
146+
147+ this . validators . map ( criteria => {
148+ this . passwordFormControl . setValidators ( Validators . pattern ( this . criteriaMap . get ( criteria ) ) ) ;
149+ } )
150+
151+ // this.passwordFormControl = new FormControl('',
152+ // [...this.validators.map(criteria => Validators.pattern(this.criteriaMap.get(criteria)))]);
144153 }
145154
146155 calculatePasswordStrength ( ) {
0 commit comments