0
我想簡單地複製從角網站上的演練,但不能得到長度驗證工作:角2:長度驗證工作不
<input
style="display:inline-block;min-width:150px"
class="form-input"
id="phone"
required
minlength="4"
maxlength="24"
type="number"
name="phone"
[(ngModel)]="client.phone"
#phone="ngModel" />
<!-- required works, minlength and maxlength always false -->
{{ phone.hasError('required') }} {{ phone.hasError('minlength') }} {{ phone.hasError('maxlength') }}
<div *ngIf="phone.errors && (phone.dirty || phone.touched)"
class="alert alert-danger">
<div [hidden]="!phone.errors.required">
Name is required
</div>
<div [hidden]="!phone.errors.minlength">
Name must be at least 4 characters long.
</div>
<div [hidden]="!phone.errors.maxlength">
Name cannot be more than 24 characters long.
</div>
</div>
我必須失去了一些東西簡單,但由於某種原因,required
驗證根據輸入而改變,但無論我的輸入有多長時間,minlength
和maxlength
總是false
。
我知道我失去了一些東西。謝謝! –
如果我不希望在提交時發生變化,該怎麼辦? –