Inputs using Angular 2’s ngModel automatically apply style classes of .ng-validand .ng-invalid each time the input’s validity changes. These classes allow you easily add your own styles simply by declaring the styles in your Componentdecorator.

import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-message',
templateUrl: './message.component.html',
styleUrls: ['./message.component.css']
})
export class MessageComponent implements OnInit { message = "Hello"; constructor() { } ngOnInit() {
} onSubmit(formValue){
console.log("formValue", JSON.stringify(formValue, null, ))
}
}
input.ng-dirty.ng-valid.ng-touched{
border-bottom: green 2px solid;
}
input.ng-invalid.ng-dirty.ng-touched{
border: 2px solid red;
}

Github

[Angular2 Form] Style Validation in Angular 2 Forms的更多相关文章

  1. [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 ...

  2. [Angular2 Form] Display Validation and Error Messaging in Angular 2

    Angular 2’s ngModel provides error objects for each of the built-in input validators. You can access ...

  3. [Angular2 Router] Style the Active Angular 2 Navigation Element with routerLinkActive

    You can easily show the user which route they are on using Angular 2’s routerLinkActive. Whenever a ...

  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] 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 ...

  6. [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 ...

  7. [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 ...

  8. Adding Validation to our Album Forms 添加类属性的一些验证特性

    Adding Validation to our Album Forms We’ll use the following Data Annotation attributes: Required – ...

  9. shit element ui & form password validation

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

随机推荐

  1. win7的centos虚拟机上搭建mysql5.6服务

    1 安装包下载 mysql5.6下载地址: http://dev.mysql.com/downloads/mysql/ 这里选择linux版本: navicat11破解版的下载地址: http://d ...

  2. Hadoop2学习记录(1) |HA完全分布式集群搭建

    准备 系统:CentOS 6或者RedHat 6(这里用的是64位操作) 软件:JDK 1.7.hadoop-2.3.0.native64位包(可以再csdn上下载,这里不提供了) 部署规划 192. ...

  3. mysql基础知识(4)--修改

    修改表: 一般概述 通常,创建一个表,能搞定(做到)的事情,修改表也能做到.大体来说,就可以做到: 增删改字段: 增:alter  table  表名  add  [column]  字段名  字段类 ...

  4. ResultMap

    Mybatis 数据库字段和对象属性的映射 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE ...

  5. CameraComponent Quality

    CameraComponent1.Quality := TVideoCaptureQuality.HighQuality; procedure TCameraComponentForm.Set720p ...

  6. C++11初始化列表

    [C++11之初始化列表] 在C++03中,在严格遵守POD的定义和限制条件的结构及类型上可以使用初始化列表(initializer list),构想是结构或是数组能够依据成员在该结构内定义的顺序通过 ...

  7. STM32先设置寄存器还是先使能时钟

    http://zhidao.baidu.com/link?url=gdVNuIgLOJcV37QzbCx0IrFip5pskiPQDWpoZayr_xBEe120p4d_iWtrfDl1d4tSFaH ...

  8. Win7系统下利用U盘安装Ubuntu14.04麒麟版

    转自http://www.360doc.cn/article/14743053_335473181.html 重要提示:在采用u盘安装ubuntu分区时,所有磁盘一定要全部设置成逻辑分区,包括根目录/ ...

  9. c++中__declspec用法总结

    “__declspec”是Microsoft c++中专用的关键字,它配合着一些属性可以对标准C++进行扩充.这些属性有:align.allocate.deprecated. dllexport.dl ...

  10. thinkPHP 无法create,无法插入数据,提示非法数据对象

    4.thinkPHP 无法create,提示非法数据对象解决方法:不要create+add,而用 data[]= '';+add$m_r_fa_account = D('R_fa_account'); ...