码迷,mamicode.com
首页 > 其他好文 > 详细

[Angular2 Form] Validation message for Reactive form

时间:2016-10-30 07:32:17      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:com   put   index   dex   ror   pre   dirty   str   can   

  <div class="form-field">
    <label>Confirm Password: </label>
    <input type="text" formControlName="confirm" [(ngModel)]="signup.confirm" name="confrim">
    <div *ngIf="!signupForm.valid">
      <span *ngIf="signupForm.get(‘confirm‘).hasError(‘confirmPassword‘) && signupForm.get(‘confirm‘).touched">
        {{signupForm.get(‘confirm‘).errors?.confirmPassword.message}}
      </span>
      <span *ngIf="signupForm.get(‘confirm‘).hasError(‘required‘) && signupForm.get(‘confirm‘).dirty">This field is requred</span>
    </div>
  </div>

 

‘signupForm‘ is a formGroup. 

we can use ‘hasError‘ & ‘get()‘ methods to write the code.

 

Refer to: Article && Doc

[Angular2 Form] Validation message for Reactive form

标签:com   put   index   dex   ror   pre   dirty   str   can   

原文地址:http://www.cnblogs.com/Answer1215/p/6012368.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!