Angular响应式表单模式不起作用。
创始人
2024-10-30 07:00:40
0
  1. 确保在模块中导入了 @angular/forms:

import { ReactiveFormsModule } from '@angular/forms';

@NgModule({ imports: [ ReactiveFormsModule, // ... ], // ... }) export class AppModule { }

  1. 在组件中导入 FormGroup、FormControl 等表单相关类:

import { Component, OnInit } from '@angular/core'; import { FormGroup, FormControl } from '@angular/forms';

@Component({ selector: 'app-my-form', template:

, }) export class MyFormComponent implements OnInit { myForm: FormGroup;

ngOnInit() { this.myForm = new FormGroup({ firstName: new FormControl(), // more form controls here }); }

onSubmit() { console.log(this.myForm.value); } }

  1. 在模板中将 form 控件绑定到 FormGroup 实例:

  1. 确保 FormControlName 和 FormControl 实例的名称匹配。例如:

new FormGroup({ firstName: new FormControl(), // FormControl 实例名为 'firstName' // ... }); // FormControlName 为 'firstName'

  1. 确保 FormControl 实例有值。例如:

new FormGroup({ firstName: new FormControl(''), // FormControl 实例值为空字符串 // ... });

  1. 检查表单控件的错误信息:

热门资讯

日前!wepoker有用吗,h... 日前!wepoker有用吗,hhpoker辅助器,教程书教程(果真有挂)-哔哩哔哩1、游戏颠覆性的策...
备受关注的!hhpoker德州... 备受关注的!hhpoker德州透视(透视)果然确实有挂(有挂技术开挂辅助安装)-哔哩哔哩1、hhpo...
此事备受玩家关注!wepoke... 此事备受玩家关注!wepoker透视辅助下载,wepoker轻量版辅助,诀窍教程(有挂规律)-哔哩哔...
出乎意料的是!wepoker私... 出乎意料的是!wepoker私局代打(透视)原来有挂(有挂秘诀开挂辅助安装)-哔哩哔哩1、点击下载安...
围绕透视问题!aapoker辅... 围绕透视问题!aapoker辅助工具安全吗,淘宝买wepoker透视有用吗,操作教程(揭秘有挂)-哔...
为了进一步!pokemmo手机... 为了进一步!pokemmo手机版透视脚本(透视)一直真的是有挂(有挂秘笈开挂辅助工具)-哔哩哔哩1、...
现就发布提示!hhpoker破... 现就发布提示!hhpoker破解工具,wepokerh5破解,手册教程(有挂分享)-哔哩哔哩1、用户...
为切实保障!德普之星的辅助工具... 为切实保障!德普之星的辅助工具介绍(透视)其实确实有挂(讲解有挂开挂辅助安装)-哔哩哔哩1、每一步都...
今天上午!wejoker手机版... 今天上午!wejoker手机版透视脚本,newpoker怎么安装脚本,讲义教程(真是有挂)-哔哩哔哩...
据统计!hhpoker可以开挂... 据统计!hhpoker可以开挂吗(透视)一直真的有挂(有挂详细开挂辅助辅助器)-哔哩哔哩1、上手简单...