[Angular2 Form] Validation message for Reactive form

  <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

posted @ 2016-10-30 05:04  Zhentiw  阅读(301)  评论(0编辑  收藏  举报