[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 ...
随机推荐
- Web表格
HTML元素学习 1:表格:表格的作用是显示表格数据,小范围内布局 表格的框架 <!doctype html> <html lang="en"> <h ...
- Python:类属性,实例属性,私有属性与静态方法,类方法,实例方法
From: http://www.cnblogs.com/pengsixiong/p/4823473.html 属性分为实例属性与类属性 方法分为普通方法,类方法,静态方法 一:属性: 尽量把需要用户 ...
- 清空easyui datagrid
$('#grid').datagrid("loadData",{total:0,rows:[]});
- 详解Android定位
相信很多的朋友都有在APP中实现定位的需求,今天我就再次超炒冷饭,为大家献上国内开发者常用到的三种定位方式.它们分别为GPS,百度和高德,惯例先简单介绍下定位的背景知识. 什么是GPS定位.基站定位和 ...
- SCU 4440 分类: ACM 2015-06-20 23:58 16人阅读 评论(0) 收藏
SCU - 4440 Rectangle Time Limit: Unknown Memory Limit: Unknown 64bit IO Format: %lld & %llu ...
- C++11无限制的unions
[C++11无限制的unions] 在标准 C++ 中,并非任意的类型都能做为 union 的成员.比方说,带有 non-trivial 构造函数的类型就不能是 union 的成员.在新的标准里,移除 ...
- ado通用操作数据单元
DELPHI开发2层C/S数据库应用程序,许多人通过ADOQUERY或ADOTABLE直接操作数据库,其实这种方法虽然最为直接,但有其缺点:如果以后要将程序升级为3层C/S会非常困难.而通过像下面的通 ...
- LIS (最长上升子序列)
LIS两种写法 O(n^2) dp[i]表示以a[i]结尾的为LIS长度 #include <algorithm> #include <iostream> #include & ...
- hdoj 5392 Infoplane in Tina Town
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5392 #include<stdio.h> #include<cstring> ...
- WebService《JavaEE6权威指南 基础篇第4版》
[Web服务] 为运行在不同平台和框架之上的软件提供了互操作的标准方式.良好的互操作性和可扩展性.消息采用自包含文档的形式. ——解决异构系统之间交互.解决异构系统通信问题: 1.通过XML,JSO ...