【发布时间】:2023-03-27 15:01:01
【问题描述】:
我的输入控件有问题,如果我输入 501(无效值),除非输入失去焦点,否则不会显示 mat-error。当用户输入无效值而不输入失去焦点时,如何显示它? 这是html
<div class="col-auto form margin-top-17 margin-left-10" [formGroup]="activationPointsFormGroup">
<mat-form-field style="width:230px!important">
<input matInput type="number" placeholder="Range" [formControl]="activationPointsFormControl"
(keydown.enter)="loadData()">
<mat-error class="margin-top-1" *ngIf="activationPointsFormControl.errors">
Valid values are between -500 and 500 and not 0
</mat-error>
</mat-form-field>
</div>
和打字稿代码
public activationPointsFormGroup: FormGroup;
public activationPointsFormControl: FormControl;
private createForm(): void {
this.activationPointsFormControl = new FormControl(1, [Validators.required, Validators.min(-500), Validators.max(500)]);
this.activationPointsFormGroup = new FormGroup({
timeThresholdFormControl: this.activationPointsFormControl,
});
this.activationPointsFormControl.valueChanges.subscribe(value => {
if (value) {
this.selectedActivationPoints = value;
}
});
}
【问题讨论】:
标签: angular angular-forms