我的格式如下:
https://stackblitz.com/edit/angular-reactive-forms-z1l7sn?file=app/app.component.html
但是我的html模板minlength从未应用到FormControl。
这永远不会引发错误。
我该如何解决?
<input matInput type="password" autocomplete="off" placeholder="input" formControlName="newPassword" required
minlength="useMinLength ? selectedMinLength : 0"
pattern="^[/\S/]+$">
答案 0 :(得分:2)
您需要在反应式表单控件中包含mininum length验证器!例如,
selectedMinLength = 6
.
.
ngOnInit(){
this.passwordForm = new FormGroup({
newPassword: new FormControl(null, [Validators.required, Validators.minLength(this.selectedMinLength)])
})
}
答案 1 :(得分:1)
固定为 https://stackblitz.com/edit/angular-reactive-forms-ncycwu
<input matInput type="password" autocomplete="off" placeholder="input" formControlName="newPassword" required
minlength="{{useMinLength ? selectedMinLength : 0}}"
pattern="^[/\S/]+$">