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的更多相关文章

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

  2. [Angular2 Form] Reactive Form, show error message for one field

    <form [formGroup]="reactiveForm" novalidate autocomplete="off"> <div cl ...

  3. Angular:Reactive Form的使用方法和自定义验证器

    本文将介绍Angular(Angular2+)中Reactive Form的有关内容,包括: Reactive Form创建方法 如何使用验证 自定义验证器 下面开始进入正文! Reactive Fo ...

  4. angular2 学习笔记 ( Form 表单 )

    refer : https://angular.cn/docs/ts/latest/guide/forms.html https://angular.cn/docs/ts/latest/cookboo ...

  5. angular reactive form

    这篇文章讲了angular reactive form, 这里是angular file upload 组件 https://malcoded.com/posts/angular-file-uploa ...

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

  7. SpringMVC form:form的一个错误(没有传到前台绑定类)

    SpringMVC form:form的一个错误(没有传到前台绑定类) 报错信息: Neither BindingResult nor plain target object for bean nam ...

  8. SpringMVC的form:form表单的使用

    为什么要使用SpringMVC的form:form表单,有两个原因:一是可以更加快捷的完成表单的开发,比如会替你做好数据类型装换等本来需要你自己动手的工作.其次就是能够更加方便的实现表单回显. 首先要 ...

  9. 【原】Oracle EBS 11无法打开Form及Form显示乱码的解决

    问题:Oracle EBS 11无法打开Form及Form显示乱码 解决: 1.尝试使用jre1.5或1.6安装目录下jre/bin/server目录里的jvm.dll替换JInitiator安装目录 ...

随机推荐

  1. 42.管道,cmd执行指令写到管道中

    #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <stri ...

  2. c#中 xml和json 互相转换

    --xml转json XmlDocument doc = new XmlDocument(); doc.LoadXml(result); string json = Newtonsoft.Json.J ...

  3. spark源码阅读

    根据spark2.2的编译顺序来确定源码阅读顺序,只阅读核心的基本部分. 1.common目录 ①Tags②Sketch③Networking④Shuffle Streaming Service⑤Un ...

  4. POJ 1269 Intersecting Lines 直线交

    不知道谁转的计算几何题集里面有这个题...标题还写的是基本线段求交... 结果题都没看就直接敲了个线段交...各种姿势WA一遍以后发现题意根本不是线段交而是直线交...白改了那个模板... 乱发文的同 ...

  5. 查看JSP和Servlet版本+

    如何查看JSP和Servlet版本 找到jsp-api.jar和servlet-api.jar ,分别打开META-INF下的MAINMEFT.MF文件,查看对应的版本. 例: JSP版本: Mani ...

  6. Linux-PS1变量详解

    1.PS1 要修改linux终端命令行颜色,我们需要用到PS1,PS1是Linux终端用户的一个环境变量,用来说明命令行提示符的设置.在终端输入命令:#set,即可在输出中找到关于PS1的定义如下: ...

  7. 003 python 注释/数据类型/运算符/输入输出/格式化输出

    集成开发环境 pycharm 工欲善其事,必先利其器 pycharm是具备一般的python ide的功能,同时呢支持调试,语法高亮,代码管理,智能提示 加快快发的速度,提高开发效率 注释 what ...

  8. 一个一线城市的IT白领的生活成本:3万/年

    自从大学毕业,经济独立,就开始全面统计各种生活开支.仔细的去统计下,发现开销还是挺大的. 定理:开销越大,就意味着你每个月的收入必须越高. 三族鼎立节余族: 收入-开支 > 0月光族:收入-开支 ...

  9. Jmeter使用_处理响应结果显示乱码

    1. 添加BeanShell PostProcessor 输入prev.setDataEncoding("utf-8"); 目的是修改响应数据编码格式为utf-8,保存

  10. CSU1660: K-Cycle

    Description A simple cycle is a closed simple path, with no other repeated vertices or edges other t ...