欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Angular模板表單校驗(yàn)方法詳解

 更新時(shí)間:2017年08月11日 15:56:13   作者:work hard work smart  
這篇文章主要為大家詳細(xì)介紹了Angular模板表單校驗(yàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Angular模板表單校驗(yàn)的方法,供大家參考,具體內(nèi)容如下

1. 創(chuàng)建指令

ng g directive directives/mobileValidator 

2. html

<form #myForm="ngForm" (ngSubmit)="onSubmit2(myForm.value, myForm.valid)">
 <div>
 <h3>登錄</h3>
 </div>
 <div>用戶名:<input ngModel required name="username" type="text" (input)="onMobileInput(myForm)"></div>
 <div [hidden]="mobileValid || moblieUntouched">
  <div [hidden]="!myForm.form.hasError('required','username')">
  用戶名是必填項(xiàng)
  </div>
 </div>
 
 <div>電話: <input ngModel mobile name="mobile" type="text"></div>
 <button type="submit">登錄</button>
</form>

3. 控制器

mobileValid: boolean = true;
moblieUntouched: boolean = true;
 
onMobileInput(form: NgForm) {
 if (form) {
 this.mobileValid = form.form.get('mobile').valid;
 this.moblieUntouched = form.form.get('mobile').untouched;
 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論