Home > Article > Web Front-end > Share some knowledge about forms in Angular
This article will share with you some knowledge points related to Angular forms. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Related tutorial recommendations: "angularjs video tutorial"
<input>
<input>
(<htmlinputelement>event.target).value</htmlinputelement>
[value]="..." 仅支持字符串值 [ngValue]="..." 支持任何类型
取值范围20-360:^(([2-9][0-9])|([1-2][0-9][0-9])|([3][0-5][0-9]))$|^[3][6][0]$ 整数:^-?d+$ 浮点数:^(-?d+)(.d+)?$ 正浮点数:^(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*))$ 负浮点数 ^(-(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*)))$ 非负浮点数(正浮点数 + 0):^d+(.d+)?$ 非正浮点数(负浮点数 + 0) ^((-d+(.d+)?)|(0+(.0+)?))$
import {Component} from '@angular/core'; import {NgForm} from '@angular/forms'; @Component({ selector: 'example-app', template: `
First name value: {{ first.value }}
First name valid: {{ first.valid }}
Form value: {{ f.value | json }}
Form valid: {{ f.valid }}
`, }) export class SimpleFormComp { onSubmit(f: NgForm) { console.log(f.value); // { first: '', last: '' } console.log(f.valid); // false } }#first="ngModel"
Export NgModel into a local variable named first. NgModel maps the properties of the FormControl instance it controls, allowing you to check the status of the control in the template, such as valid and dirtyngModel
<input> tag, the system will automatically create an object called <code>FormControl
for this tag, and automatically add it to FormGroup
. The FormControl
is identified in FomGroup
by the name
attribute on the <input>
tag, so ## must be added. #name attribute.
import { Component, OnInit } from '@angular/core'; import {Data} from "popper.js"; @Component({ selector: 'app-test-data', template: `test-data works!
<input>{{date}}
<input>{{month}}
<input>{{week}}
<input>{{time}}
<input>{{datetimeLocal}} <input> `, styles: [ ] }) export class TestDataComponent implements OnInit { date:string; month:string; week:string; time:string; datetimeLocal:string; constructor() { } ngOnInit(): void { } }
Programming Video Course! !
The above is the detailed content of Share some knowledge about forms in Angular. For more information, please follow other related articles on the PHP Chinese website!