[Angular 2] ng-control & ng-control-group
2015-11-06 02:40
633 查看
Control:
Controls encapsulate the field's value, a states such as if it is valid, dirty or has errors.
ControlGroup:
A way to manage multiple Controls.
Controls encapsulate the field's value, a states such as if it is valid, dirty or has errors.
var nameControl = new Control("Nate"); var name = nameControl.value; // -> Nate nameControl.errors // -> StringMap<string, any> of errors nameControl.dirty // -> false nameControl.valid // -> true
ControlGroup:
A way to manage multiple Controls.
var personInfo = new ControlGroup({ firstName: new Control("Nate"), lastName: new Control("Murray"), zip: new Control('90210') }); personInfo.value; // ->{ //firstName: "Nate", //lastName: "Murray", //zip: "90210" } personInfo.errors // -> StringMap<string, any> of errors personInfo.dirty // -> false personInfo.valid // -> true
import {Component, View, FORM_DIRECTIVES} from 'angular2/angular2'; @Component({ selector: 'demo-form-sku' }) @View({ directives: [FORM_DIRECTIVES], template: ` <div> <h2>Demo Form: Sku</h2> <!-- ngForm is attched to the form, and #f="form" form is also come from ngForm--> <form #f = "form" (submit)="onSubmit(f.value)"> <div class="form-group"> <label for="skuInput">SKU</label> <input type="text" class="form-control" id="skuInput" placeholder="SKU" ng-control="sku"> </div> <button type="submit" class="btn btn-default"> Submit </button> </form> </div> ` }) export class DemoFormSku { constructor() { } onSubmit(value){ console.log(value); } }
相关文章推荐
- [Angular 2] NgNonBindable
- angular 指令简述
- ionic工程组织文件
- AngularJS API之$injector ---- 依赖注入
- angularjs初窥门径
- AngularJs ngChange、ngChecked、ngClick、ngDblclick
- AngularJS 最常用的八种功能
- $resource 数据交互插件
- angularjs ngSanitize ngRoute ngAnimate 插件
- Angularjs 自定义服务 provide 里 provider 方法 以及 factory、 service 方法以及 provider 供应商的概念
- Angularjs filter 过滤器以及自定义 filter 过滤器详解
- Angularjs 事件指令 input 相关指令 和样式指令 DOM 操作指令详解
- Angularjs 工具方法 以及 Angularjs 中使用 jquery
- angularjs学习笔记【不定期更新】
- angular源码分析:angular中的依赖注入式如何实现的
- angular-file-upload 中文API
- AngularJS的directive(指令)配置选项说明
- angularJS常见问题汇总
- angularJs自定义模块
- AngularJS 中文资料+工具+库+Demo 大搜集