This article mainly introduces the form response function of Angular4 programming, and analyzes the specific implementation steps and related operating techniques of the Angular4 form response function in the form of examples. Friends in need can refer to it. I hope it can help everyone.
Responsive form
1. The responsive form needs to inject the responsive form module into the appmodule file
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; <!-- 这里引用模块的时候要注意,具体是哪个module文件使用了表单, 因为在某些情况下表单是被appmodule下的某个子module文件使用, 那么就要在该子module文件中引入响应式表单模块。 --> @NgModule( {imports: [FormsModule, ReactiveFormsModule……] ……}
2. Reference
in the form.component.ts component. The first way:
import { Component } from '@angular/core'; import { FormGroup, FormControl, FormBuilder} from '@angular/forms'; @Component({ templateUrl: 'forms.component.html' }) export class FormsComponent { formModel: FormGroup; constructor(fb: FormBuilder) { this.formModel= fb.group({ formControl1: [''], formControl2: [''], …… }); } onSubmit () { console.log(this.formModel.value); } }
Second way:
import { Component } from '@angular/core'; import { FormGroup, FormControl} from '@angular/forms'; @Component({ templateUrl: 'forms.component.html' }) export class FormsComponent { formModel: FormGroup; /*这里定义表单变量名,HTML文件中绑定时使用*/ constructor() { this.formModel= new FormGroup({ formControl1: new FormControl(), formControl2: new FormControl(), …… }); } onSubmit () { console.log(this.formModel.value); } }
3. Corresponding HTML file
<form action="" method="post" [formGroup]='formModel'> <!-- 通过指令绑定ts文件中命名的变量名 --!> <p class="form-group row"> <p class="col-md-6"> <p class="row"> <label>formControl1</label> <input type="text" formControlName='formControl1'> </p> </p> <p class="col-md-6"> <p class="row"> <label>formControl2</label> <input type="text" formControlName='formControl2'> </p> </p> </p> </form>
Detailed explanation of the input properties and output properties of Angular4
Project preparation and environment building operations in Angular4
About Angular4.0 data binding matters
The above is the detailed content of Angular4 form response function example analysis. For more information, please follow other related articles on the PHP Chinese website!

Python函数介绍:exec函数的介绍及示例引言:在Python中,exec是一种内置函数,它用于执行存储在字符串或文件中的Python代码。exec函数提供了一种动态执行代码的方式,使得程序可以在运行时根据需要生成、修改和执行代码。本文将介绍exec函数的使用方法,并给出一些实际的代码示例。exec函数的使用方法:exec函数的基本语法如下所示:exec

Python函数介绍:abs函数的用法和示例一、abs函数的用法介绍在Python中,abs函数是一个内置函数,用于计算给定数值的绝对值。它可以接受一个数字参数,并返回该数字的绝对值。abs函数的基本语法如下:abs(x)其中,x是要计算绝对值的数值参数,可以是整数或浮点数。二、abs函数的示例下面我们将通过一些具体的示例来展示abs函数的用法:示例1:计算

Python函数介绍:sorted函数的功能和示例Python是一门非常强大的编程语言,拥有丰富的内置函数和模块。在这个系列文章中,我们将逐一介绍Python常用的函数,并提供相应的示例来帮助读者更好地理解和应用这些函数。本篇文章将详细介绍sorted函数的功能和示例。sorted函数用于对可迭代对象进行排序,并返回排序后的新列表。可以用于对数字、字

PHP中endwhile关键字的作用和示例在PHP中,endwhile是一种控制结构,用来实现while循环。它的作用是让程序在满足指定条件的情况下,重复执行一段代码块,直到条件不再满足。endwhile的语法形式如下:while(condition)://循环体代码endwhile;在这个语法中,condition是一个逻辑表达式,当该表达

Python函数介绍:filter函数的作用和示例Python是一种功能强大的编程语言,提供了许多内置的函数,其中之一就是filter函数。filter函数用于过滤列表中的元素,并返回满足指定条件的元素组成的新列表。在本文中,我们将介绍filter函数的作用,并提供一些示例来帮助读者理解其用法和潜力。filter函数的语法如下:filter(function

在PHP中,有很多实用的函数可以帮助我们更方便地处理数组。其中,array_walk()函数就是一个非常实用的函数,它可以对数组中的每个元素进行指定的操作,让我们来了解一下。array_walk()函数介绍array_walk()函数是一个用于处理数组的函数,它的语法结构如下:array_walk(array&$array,callable$callb

Python函数介绍:zip函数的介绍及示例Python是一种高级语言,它提供了许多有用的函数来帮助开发人员快速地编写程序。其中一个函数就是zip函数。Zip函数是Python中的内置函数之一,它可以接受一组可迭代对象(包括列表、元组、集合和字典等),并返回一个由这些可迭代对象中的元素按顺序成对组成的元组。Zip函数可以用于多种情况,例如:1.将两个列表的元

PHP中var关键字的作用和示例在PHP中,var关键字用于声明一个变量。以前的PHP版本中,使用var关键字是声明成员变量的惯用方式,现在已经不再推荐使用。然而,在某些情况下,var关键字依然会被使用。var关键字主要用于声明一个局部变量,并且会自动将该变量标记为局部作用域。这意味着该变量仅在当前的代码块中可见,并且不能在其他函数或代码块中访问。使用var


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!
