I have set a variable called MIN_PW
above the export class MyComponent
. The intellisense recognizes it in my formBuilder
, but it is not displaying properly in the UI (UI shows "Password must contain at least characters").
Initially, I had defined the variable within the export class
and it was working fine. However, I received advice to use const
and move it above the component.
Component file:
const MIN_PW = 12;
export class MyComponent implements OnInit {
myFormGroup = this.formBuilder.group({
password: new FormControl(null, [Validators.required, Validators.minLength(MIN_PW)]),
// etc
})
}
Template file:
<mat-form-field class="password-field">
<mat-error *ngIf="myFormGroup.controls['password'].invalid">Password must contain at least {{MIN_PW}} characters.</mat-error>
</mat-form-field>