[Angular2 Form] Reactive Form, FormBuilder
Import module:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MessageComponent } from './message.component';
import messageRoutes from './message.routes';
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
messageRoutes
],
declarations: [MessageComponent]
})
export default class MessageModule { }
Define the html:
<form [formGroup]="reactiveForm" novalidate autocomplete="off">
<div class="form-field">
<label>Title:</label>
<input formControlName="title">
</div>
<div class="form-field">
<label>Description:</label>
<input formControlName="description">
</div>
<div class="form-field">
<button type="submit">Submit</button>
</div>
</form>
ts:
reactiveForm: FormGroup;
constructor(fb: FormBuilder) {
this.reactiveForm = fb.group({
title: [
'Title',
[
Validators.required,
Validators.minLength()
]
],
description: [
'Description',
[Validators.required]
]
})
}
}
group() function take an object param, each object stands for a field in template, which refer to 'formControlName'.
// title <-- formControlName="title"
title: [
'Title', // <-- Default value
[
Validators.required,
Validators.minLength()
] // <-- Validations
],
[Angular2 Form] Reactive Form, FormBuilder的更多相关文章
- [Angular2 Form] Reactive form: valueChanges, update data model only when form is valid
For each formBuild, formControl, formGroup they all have 'valueChanges' prop, which is an Observable ...
- [Angular2 Form] Reactive Form, show error message for one field
<form [formGroup]="reactiveForm" novalidate autocomplete="off"> <div cl ...
- Angular:Reactive Form的使用方法和自定义验证器
本文将介绍Angular(Angular2+)中Reactive Form的有关内容,包括: Reactive Form创建方法 如何使用验证 自定义验证器 下面开始进入正文! Reactive Fo ...
- angular2 学习笔记 ( Form 表单 )
refer : https://angular.cn/docs/ts/latest/guide/forms.html https://angular.cn/docs/ts/latest/cookboo ...
- angular reactive form
这篇文章讲了angular reactive form, 这里是angular file upload 组件 https://malcoded.com/posts/angular-file-uploa ...
- [Angular] Reactive Form -- FormControl & formControlName, FormGroup, formGroup & formGroupName
First time dealing with Reactive form might be a little bit hard to understand. I have used Angular- ...
- SpringMVC form:form的一个错误(没有传到前台绑定类)
SpringMVC form:form的一个错误(没有传到前台绑定类) 报错信息: Neither BindingResult nor plain target object for bean nam ...
- SpringMVC的form:form表单的使用
为什么要使用SpringMVC的form:form表单,有两个原因:一是可以更加快捷的完成表单的开发,比如会替你做好数据类型装换等本来需要你自己动手的工作.其次就是能够更加方便的实现表单回显. 首先要 ...
- 【原】Oracle EBS 11无法打开Form及Form显示乱码的解决
问题:Oracle EBS 11无法打开Form及Form显示乱码 解决: 1.尝试使用jre1.5或1.6安装目录下jre/bin/server目录里的jvm.dll替换JInitiator安装目录 ...
随机推荐
- Strtus2学习
Struts 2 体系结构 : 1.Web浏览器请求一个资源. 2.过滤器Dispatcher查找方法,确定适当的Action. 3.拦截器自动对请求应用通用功能,如验证和文件上传操作. 4.Acti ...
- Android实现QQ分享及注意事项
一.获取APPID和帮助文档 在前面我介绍了关于Android中微信分享的文章< Android实现微信分享及注意事项>这一篇文章来看看关于QQ分享. 可以参看新手引导和接入说明:http ...
- mysql字符设置乱码问题
在操作系统中对于任意一个字符而言是没有编码格式概念的:同样的字母在不同的编码集里面可能代表不同的东西:关键在于你用什么样的软件打开它,软件本身是以什么样的编码格式来显示你的字符,那么你的字符当前就是什 ...
- WebService 获取客户端 IP 和 MAC 等信息
IP地址 public string getClientIP() { string result = HttpContext.Current.Request.ServerVariables[" ...
- LuoguP2765 魔术球问题(最大流)
题目描述 «问题描述: 假设有n根柱子,现要按下述规则在这n根柱子中依次放入编号为1,2,3,...的球. (1)每次只能在某根柱子的最上面放球. (2)在同一根柱子中,任何2个相邻球的编号之和为完全 ...
- ElasticSearch 5.2.2 集群环境的搭建
在之前 ElasticSearch 搭建好之后,我们通过 elasticsearch-header 插件在查看 ES 服务的时候,发现 cluster-health 显示的是 YELLOW. Why? ...
- Linux 内建命令和系统命令
shell内建命令是指bash(或其它版本)工具集中的命令.一般都会有一个与之同名的系统命令,比如bash中的echo命令与/bin/echo是两个不同的命令,尽管他们行为大体相仿.当在bash中键入 ...
- fg、bg、jobs、&、 ctrl+z---系统任务
系统任务有关的命令 一.& 这个用在一个命令的最后,可以把这个命令放到后台执行 二.ctrl + z 可以将一个正在前台执行的命令放到后台,并且暂停 一和二的区别(&放入后 ...
- Python day3 知识回顾
names = ["Jonathen","Joesph","Jotaro","Josuke",["Mea&qu ...
- 洛谷——P2590 [ZJOI2008]树的统计
https://www.luogu.org/problem/show?pid=2590#sub 题目描述 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w. 我们将以下面的形式来要求你对这 ...