首页 > 其他 > 详细

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

时间:2016-10-27 08:00:07      阅读:241      评论:0      收藏:0      [点我收藏+]
<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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!