[Angular2 Form] Understand the Angular 2 States of Inputs: Pristine and Untouched
Angular 2’s ngModel exposes more than just validity, it even gives you the states of whether the input has been “touched” or changed. This lesson explains and compares those states so you can use them to make complex validity requirements.
<form name="myForm2" #formRef2="ngForm" (ngSubmit)="onSubmit(formRef2.value)">
<fieldset ngModelGroup="login">
<legend>Login:</legend> Username: <input type="text" name="username" #usernameRef="ngModel" ngModel required>
Password: <input type="password" name="password" #passwordRef="ngModel" ngModel required> </fieldset>
</form>
<div class="error-messages" *ngIf="!formRef2.valid">
<span class="error-message" *ngIf="!usernameRef.untouched && usernameRef.errors?.required">Username is required</span>
<span class="error-message" *ngIf="!passwordRef.untouched && passwordRef.errors?.required">password is required</span>
</div>
<pre>
username pristine: {{usernameRef.pristine}}
username dirty: {{usernameRef.dirty}}
username untouched: {{usernameRef.untouched}}
username touched: {{usernameRef.touched}}
form value: {{formRef2.value | json}}
form valid: {{formRef2.valid | json}}
</pre>
[Angular2 Form] Understand the Angular 2 States of Inputs: Pristine and Untouched的更多相关文章
- [Angular2 Router] Understand the Angular 2 Base href Requirement
The <base href=”/”/> you define will determine how all other assets you plan on loading treat ...
- [Angular2 Animation] Control Undefined Angular 2 States with void State
Each trigger starts with an “undefined” state or a “void” state which doesn’t match any of your curr ...
- [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 ...
- [Angular2 Form] Build Select Dropdowns for Angular 2 Forms
Select Dropdowns in Angular 2 a built with select and option elements. You use *ngFor to loop throug ...
- [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 ...
- [Angular2 Form] Create and Submit an Angular 2 Form using ngForm
Forms in Angular 2 are essentially wrappers around inputs that group the input values together into ...
- [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 ...
- [Angular2 Form] Style Validation in Angular 2 Forms
Inputs using Angular 2’s ngModel automatically apply style classes of .ng-validand .ng-invalid each ...
- [Angular2 Form] Group Inputs in Angular 2 Forms with ngModelGroup
The ngModelGroup directive allows you to group together related inputs so that you structure the obj ...
随机推荐
- js 判断输入是否为正整数
javascript代码如下: var re = new RegExp("^[1-9][0-9]*$"); if (re.test("11k")) { cons ...
- 高级正则表达式技术(Python版)
正则表达式是从信息中搜索特定的模式的一把瑞士军刀.它们是一个巨大的工具库,其中的一些功能经常被忽视或未被充分利用.今天我将向你们展示一些正则表达式的高级用法. 举个例子,这是一个我们可能用来检测电话美 ...
- php 高效分页
mysql.php 获取数据库中的记录,完全个人经验总结,仅供参考!<?php/***PHP+MYSQL数据库基本功能*http://blog.csdn.net/yown*/########## ...
- Chapter15:派生类
在C++语言中,基类将类型相关的函数与派生类不做改变直接继承的函数区别对待,对于某些函数,基类希望它的派生类各自定义适合自身的版本,此时基类就将这些函数声明为虚函数. 派生类必须将其继承而来的成员函数 ...
- 2015-10-27 js
1.声明变量: 2.prompt属性的使用: prompt("提示框的标题","提示框的输入提示内容"); prompt的调用结果就是他输入框内的内容!!! 3 ...
- ps 图片提取线稿方法2种 转
- about云资源共享
Nosql资源: http://www.aboutyun.com/thread-5655-1-1.html (1)redis安置(2)RedisAdminUI.zip(3)redis安装部署(4) ...
- 原生JS默认设置默认值的写法
json=json||{};json.type=json.type||'get';json.data=json.data||{};json.time=json.time||2000;
- UTC+0800是什么意思
<%@ language="javascript" %> <html> <body> <% var d=new Date() var h= ...
- Tagged Pointers
[Tagged Pointers] 1.what is tagged pointer? 2.原理剖析