例如,我有這樣的形式:Angular2:得到驗證限制
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<input type="text" formControlName="username">
<div ngxErrors="username">
<div ngxError="required" [when]="['dirty', 'touched']">
Username is required
</div>
</div>
<input type="text" formControlName="password">
<div ngxErrors="password">
<div ngxError="required" [when]="['dirty', 'touched']">
Password is required
</div>
<div [ngxError]="['minlength', 'maxlength']" [when]="['dirty', 'touched']">
5 characters minimum, 12 characters maximum
</div>
</div>
</form>
與此控制器:
export class AppComponent implements OnInit {
form: FormGroup;
constructor(
private fb: FormBuilder
) {}
ngOnInit() {
this.form = this.fb.group({
username: ['', [Validators.required]],
password: ['', [Validators.required, Validators.minLength(5), Validators.maxLength(12)]]
});
}
}
我怎樣才能得到我的最大長度&值MINLENGTH?所以,我可以改變:
5 characters minimum, 12 characters maximum
這樣的: {{form.get('username').minlength}} characters minimum, {{form.get('username').maxlength}} characters maximum
這可能嗎?