我使用角度,我使用Form,特别是模板驱动的形式。特别是我有一个可以为零的数字,它必须有两个小数位,所以:
<form (ngSubmit)="onSubmitForm()" #search="ngForm">
<input type="text" ngModel class="form-control" name="search_
Home" required min=0>
<button class="btn btn-primary" type="submit" [disabled]="!search.valid">Submit</button>
</form>
问题是当我没有放任何东西时按钮被禁用但是如果我把值“-3”按钮变得可点击但是它不正确。任何人都可以帮助我?
HTML
<form (ngSubmit)="onSubmitForm()" #search="ngForm">
<input type="text" [ngModel]="searchHome" (input)="isNumber($event)" class="form-control" name="search_
Home" required min=0>
<button class="btn btn-primary" type="submit" [disabled]="isFormValid">Submit</button>
</form>
零件:
isBtnSubmitDisabled = true;
isNumber(value){
if(value && /* cond */){
this.isBtnSubmitDisabled = false;
}
}
get isFormValid(){
return this.isBtnSubmitDisabled;
}