You can watch for form / control changes by using .valueChanges.observe({...}):

        this.sku.valueChanges.observer({
next: (value)=>{
console.log("sku has changed to: " , value);
}
}) this.myForm.valueChanges.observer({
next: (value)=>{
console.log("form has change to: ",value);
}
})

Code:

import {Component, View, FORM_DIRECTIVES, Validators, FormBuilder, NgIf} from 'angular2/angular2';

@Component({
selector: 'demo-form-sku'
})
@View({
directives: [FORM_DIRECTIVES, NgIf],
template: `
<div>
<h2>Demo Form: Sku</h2>
<!-- ngForm is attched to the form, and #f="form" form is also come from ngForm-->
<form [ng-form-model]="myForm"
(submit)="onSubmit(myForm.value)">
<div class="form-group" [class.has-error]="!sku.valid && sku.touched">
<label for="skuInput">SKU</label>
<input type="text"
class="form-control"
id="skuInput"
#sku = "form"
placeholder="SKU"
[ng-form-control]="myForm.controls['sku']">
</div>
<div *ng-if="!sku.control.valid"
class="bg-warning">SKU is invalid</div>
<button type="submit" class="btn btn-default">Submit
</button>
<div *ng-if="sku.control.hasError('invalidSku')">
SKU is required
</div> </form>
<div *ng-if="!myForm.valid"
class="bg-warning">Form is invalid</div>
</div>
`
}) export class DemoFormSku {
myForm: ControlGroup;
constructor(fb:FormBuilder) {
this.myForm = fb.group({
"sku": ["", Validators.compose([
Validators.required,
skuValidator
])]
});
this.sku = this.myForm.controls['sku']; this.sku.valueChanges.observer({
next: (value)=>{
console.log("sku has changed to: " , value);
}
}) this.myForm.valueChanges.observer({
next: (value)=>{
console.log("form has change to: ",value);
}
})
} onSubmit(value){
console.log(value);
} function skuValidator(control){
if(!control.value.match(/^123/)){
return {invalidSku: true};
}
}
}

[Angualr 2] Watch for changes的更多相关文章

  1. angualr Material Icons

    首先需要项目引入 angualr meterial icons的资源库 图标资源链接 https://klarsys.github.io/angular-material-icons/ <md- ...

  2. angualr 实现tab选项卡功能

    tab.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  3. [Angualr 2] Using FormBuilder

    There are two main functions we’ll use on FormBuilder: • control - creates a new Control• group - cr ...

  4. ng-clip angualr 的copy功能

    每次写博客都想由衷的给我的老大膜拜一番!以前刚开始做angular的项目的时候就有说要有点击复制的功能因为当时菜啊,不懂啊.也就没做,今天老大又给了我一个资料!“ng-clip”.跟着老大最大的收获就 ...

  5. angualr高级篇之elem.scope()、elem.isolateScope和$compile(elem)(scope)中scope的区别

    在angular的使用过程中我们经常用$rootScope.$new()为elem创建一个新的作用域scope,然后使用$compile(elem)(scope)编译这个含有指令的元素.那么这里传进去 ...

  6. windows 下运行angualr/material2 项目

    第一步:到github上clone  angular/material2 项目 第二步:npm install 第三步: 打开git bash (cmd 或 powershell 是无法成功运行该项目 ...

  7. angualr跨域访问配置

    浏览器对于javascript的同源策略的限制,例如a.cn下面的js不能调用b.cn中的js,对象或数据(因为a.cn和b.cn是不同域),所以跨域就出现了: 简单的解释就是相同域名,端口相同,协议 ...

  8. Angualr学习笔记

    0.安装即环境初始化 下载node至windows,点击安装,所有环境变量直接OK: linux下载tar后,解压,在/etc/profile的path路径下增加node执行路径: export PA ...

  9. 学习angualr之前需要了解的typeScript知识

    官网 : www.typescriptlang.org   1.编译型语言 2.强类型语言 3.真正的面向对象的语言: 有借口.有泛型.有枚举.有访问修饰符 AMD类型的面向对象的语言     npm ...

随机推荐

  1. xubuntu14.04截图,彻底到Linux一个半月后记

        前言 自学计算机技术,越到后面,越依赖ubuntu,以致于很多时候都是一开机就打开虚拟机上的ubuntu10.04,Linux已经变得越来越重要了. 2014-04-17,ubuntu14.0 ...

  2. 假金币问题-PKUacm1029-ACM

    假金币 “Gold Bar”银行收到可靠消息:在前次的N 个金币中有一枚重量不同的假金币(其他金币的重量都相同).经济危机之后他们只有一台天平可用.用这台天平,可以称量出左边托盘中的物体是轻于.重于或 ...

  3. dedecms织梦二级菜单的实现方法

    首先,复制代码: 程序代码 {dede:channelartlist typeid='top' cacheid='channelsonlist'} {dede:channel type='son' n ...

  4. ecshop数据库操作类

    ECShop v2.7.2没有使用一些开源的数据库操作类,比如adodb或者PEAR,而是封装了自己的实现. 好处:实现非常轻量,只有一个文件,27Kb,大大减小了分发包的文件大小. 当网站需要做me ...

  5. python连接mysql之pymysql模块

    以下demo均以python2中的mysqldb模块 一.插入数据 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import MySQLdb    conn = MyS ...

  6. 转:使用Mongo Connector和Elasticsearch实现模糊匹配

    原文来自于:http://www.csdn.net/article/2014-09-01/2821485-how-to-perform-fuzzy-matching-with-mongo-connec ...

  7. PLSQL 看连接数据库的用户

    1. PLSQL选用SYSDBA登录,用户sys,密码xxx 2. 登录后,点tools菜单有sessions子菜单, 3.点击sessions子菜单,可以看到连接用户

  8. ios入门之c语言篇——基本函数——1——随机数生成

    1.随机数函数 参数返回值解析: 参数: a:int,数字范围最小值: b:int,数字范围最大值: 返回值: 1:闰年: 0:非闰年: 备注: a-b的绝对值不能超过int的最大值(65535); ...

  9. Intra Luma Prediction

    在宏块的帧内预测过程中,有四种宏块类型:I_4x4,I_8x8,I16x16,I_PCM.他们都需要在相邻块做去块滤波之前进行帧内预测. 亮度帧内预测的总体流程 1-4获取当前block的帧内预测模式 ...

  10. 使用next-key locks 用于搜索和索引扫描,可以防止幻读

    Next-Key Locks A next-key lock is a combination of a record lock on the index record and a gap lock ...