Angular 2’s ngModel provides error objects for each of the built-in input validators. You can access these errors from a reference to the ngModel itself then build useful messaging around them to display to your users.

First, you can use 'ngModel' from 'FormsModule' from angualr2 build module.

<section>
Min length & required: <input type="text" [(ngModel)]="message" #messageRef="ngModel" required minlength="5">
<pre>
Errors: {{messageRef.errors | json}}
Valid: {{messageRef.valid}}
</pre>
<div *ngIf="!messageRef.valid">
<div *ngIf="messageRef.errors?.required">This field is required</div>
<div *ngIf="messageRef.errors?.minlength">Min length is {{messageRef.errors?.minlength.requiredLength}}, but now only {{messageRef.errors?.minlength.actualLength}}</div>
</div>
<br />
<hr/> <button md-button class="md-raised">Add</button>
</section>

Github

[Angular2 Form] Display Validation and Error Messaging in Angular 2的更多相关文章

  1. [Angular2 Form] Style Validation in Angular 2 Forms

    Inputs using Angular 2’s ngModel automatically apply style classes of .ng-validand .ng-invalid each ...

  2. shit element ui & form password validation

    shit element ui & form password validation shit docs https://github.com/yiminghe/async-validator ...

  3. [Angular2 Form] Model Driven Form Custom Validator

    In this tutorial we are going to learn how simple it is to create custom form field driven validator ...

  4. [Angular2 Form] Angular 2 Template Driven Form Custom Validator

    In this tutorial we are going to learn how we can also implement custom form field validation in Ang ...

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

    <form [formGroup]="reactiveForm" novalidate autocomplete="off"> <div cl ...

  6. [Angular2 Form] Validation message for Reactive form

    <div class="form-field"> <label>Confirm Password: </label> <input typ ...

  7. Oracle Form Developer: Folder FRM-99999 Error 14212

    Question: 做FOLDER文件夹功能,打开FORM错误提示: FRM-99999:出现1412错误.有关该错误的详细信息,请参阅发行说明文件(relnotes) Answer: 原因是FOLD ...

  8. [Angular2 Form] Create Radio Buttons for Angular 2 Forms

    Using Radio Buttons in Angular 2 requires a basic understanding of forms as well as how their labels ...

  9. [Angular2 Form] Use RxJS Streams with Angular 2 Forms

    Angular 2 forms provide RxJS streams for you to work with the data and validity as it flows out of t ...

随机推荐

  1. 数往知来 ADO.NET <八>

    ADO.NET基础 学习目的:通过程序访问数据库 ,ADO.NET就是一组类库, -->connection   用来连接数据库的类 语法:首先需要一个连接字符串 -->以SQL serv ...

  2. 移动开发必备!15款jQuery Mobile插件

    移动互联网的发展,来自PC端的网页并不能完全自适应移动端页面需求,使得响应式设计体验产生并成为潮流,也正是这样一种需求,促成了jQuery Mobile的流行.jQuery Mobile这样一款基于j ...

  3. WS之cxf的权限拦截器应用

    一.服务器端: 1.权限判断: package cn.tdtk.ws.interceptor; import java.util.List; import org.apache.cxf.binding ...

  4. 【原创译文】基于Docker和Rancher的超融合容器云架构

    基于Docker和Rancher的超融合容器云架构 ---来自Rancher和Redapt 超融合架构在现代数据中心是一项巨大的变革.Nutanix公司发明了超融合架构理论,自从我听说他们的“iPho ...

  5. Google Glass应用开发探索

    摘要:2012年6月的Google开发者大会上,作者有幸预定到了Google Glass.8个月后,她收邀参加了Google纽约总部举行的Google Glass Foundry开发大赛.在为期两天的 ...

  6. phonegap 新窗口 inappbrowser插件

    在Phonegap 开发过程中,需要调用外部网页,又要跳出白名单安全限制,可以使用 inappbrowser插件. http://plugins.cordova.io/#/package/org.ap ...

  7. Python程序的混淆和加密

    混淆 为了增加代码阅读的难度, 源代码的混淆非常必要, 一个在线的Python代码混淆网站. 如果你觉得有用, 可以购买离线版本.同时需要注意的是, 这个混淆其实还是被很多人怀疑的, 因为即使混淆了, ...

  8. <转载>gcc/g++编译

    转载于:http://www.cnblogs.com/yc_sunniwell/archive/2010/07/22/1782678.html 1. gcc/g++在执行编译工作的时候,总共需要4步 ...

  9. STM32 常用GPIO操作函数记录

    STM32读具体GPIOx的某一位是1还是0 /** * @brief Reads the specified input port pin. * @param GPIOx: where x can ...

  10. OSPF虚链路配置.示例1

      在OSPF 网络中,区域0为骨干区域,其它的为非骨干区域,非骨干区域必须与骨干区域直接相连. 根据拓扑图可看到区域1与骨干区域0直接相连而区域2与骨干区域没有直接相连,这种情况下我们可以创建一条虚 ...