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

[Angular2 Form] Reactive Form, show error message for one field

时间:2016-10-27 08:00:19      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:status   pre   with   using   log   orm   display   case   error   

<form [formGroup]="reactiveForm" novalidate autocomplete="off">
  <div class="form-field">
    <label>Title:</label>
    <input formControlName="title">
    <div class="field-error-message" *ngIf="reactiveForm.controls.title.errors?.required">
      Title is required
    </div>
</form>

In this tutorial we are going to learn how we mark form fields in error and display error messages to the user in the case of Angular 2 model driven forms. We will see that the approach is similar than what we did while using template driven forms, but in this case we don‘t have template exports available.

We are going to see how the FormControl api exposes a list of controls each with a separate status and its own list of errors, and how that can be used to display messages to the user.

[Angular2 Form] Reactive Form, show error message for one field

标签:status   pre   with   using   log   orm   display   case   error   

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

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