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. mvc中@RenderSection()研究

    一.@RenderSection定义 HelperResult RenderSection(string name) 但是当如果使用了_Layout.cshtml做母版页的页没有实现Section的话 ...

  2. 服务器安装Linux应该注意的问题

    安装方式: 1.光盘安装 2.睿捷引导安装 3.u盘安装 4.硬盘安装 5.IPMI远程安装 其中,睿捷是最方便的方式,驱动直接都会安装好,但是睿捷支持的Linux系统只有两个,局限性比较大: 光盘和 ...

  3. .net调用java webservice基于JBOSS服务器 学习笔记(一)

    1.遇到数组类型或List等复杂数据类型是,需要对其进行包装,就是将复杂数据类型放到一个类里面: public class VOCargoJTWS { /** JT列表 */ private List ...

  4. NServiceBus-架构的原则

    自主性和松散耦合在设计时和运行时都是没有的事,任何技术都可以给你. 面向服务的架构(SOA)和事件驱动的体系结构提供了依据识别使用nservicebus. 战略领域驱动设计有助于弥合业务/IT鸿沟和驱 ...

  5. HW7.14

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  6. koa 笔记 运行错误

    按照 演示的代码 直接运行会出错,大家需要调整方式. http://koajs.cn/ 要安装以下 $ npm install -g n$ n 0.11.12$ node --harmony my-k ...

  7. koa redis 链接

    koa 是新一代框架 npm install koa-redis 代码如下 var koa = require('koa'); var http = require('http'); var sess ...

  8. U盘分区信息清除

    diskpart select disk 1 clean 清除选中(优U)盘的所有信息;

  9. Rdlc报表出现空白页解决方法

    在使用RDLC报表时,碰到这种情况:当只有一页数据时,报表确显示两页,第二页除了报表头之外数据为空.然后,当有多页数据时,最后一页为空. RDLC報表設計好後,在ReportViewer預覽報表時,頁 ...

  10. C++11对象构造的改良

    [C++11对象构造的改良] C++03中一个构造函数无法构造另一个构造函数,因为A()实际上意味着生成一个临时对象,存在语音混淆.详情请看参考2. C++11中允许直接在初始化列表中调用其它的构造函 ...