component.ts
this.companySettingsForm = this.formBuilder.group({
'delivary_charge': ['', Validators.compose([Validators.required, ])],
});
this.delivary_charge = this.companySettingsForm.controls['delivary_charge'];
}在Component.html中,我添加了min和max值,但是它不能工作
component.html
<input pInputText #value type="number" [formControl]="surcharge" min="1"
max="9999999999999" class="input-width">发布于 2019-02-28 13:30:34
可以在窗体控件中使用Validators.minLength()和Validators.maxLength()设置窗体控件的最小和最大长度。
要检查负值,可以使用Validators.min()
this.companySettingsForm = this.formBuilder.group({
'delivary_charge': ['', Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(10), Validators.min(0)])],
});发布于 2019-02-28 13:56:06
您还可以像下面这样限制/检查component.ts中的负值
myControl:FormControl = new FormControl();
this.myControl.valueChanges.subscribe(val=>{
if(val<0){
// you can check negative values here and do whatever you'd like
// you can also set the value of your input to null or 0 to prevent negative values
// this.myControl.setValue(null);
}
});https://stackoverflow.com/questions/54926884
复制相似问题