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有没有... 透视步骤!wepoker有没有挂(WePoKer私人局)一直是有辅助攻略(哔哩哔哩)1、每一步都需要...
透视讲义!wepoker透视脚... 透视讲义!wepoker透视脚本是什么(WPK辅助)确实真的是有辅助神器(哔哩哔哩)1、wepoke...
透视经验!poker worl... 透视经验!poker world辅助器(WePoKer h5)真是存在有辅助app(哔哩哔哩)pok...
透视诀窍!德州局怎么透视(HH... 透视诀窍!德州局怎么透视(HHpoker脚本)切实是真的有辅助工具(哔哩哔哩)小薇(辅助器软件下载)...
透视操作!we-poker软件... 透视操作!we-poker软件(HHpoker有用)总是有辅助app(哔哩哔哩)1、透视操作!we-...
透视法门!sohoopoker... 透视法门!sohoopoker辅助(WePoKer运气)原来有辅助攻略(哔哩哔哩)1、下载好soho...
透视法子!大菠萝手游辅助(WP... 透视法子!大菠萝手游辅助(WPK透视)本来真的是有辅助方法(哔哩哔哩)1、许多玩家不知道大菠萝手游辅...
透视手册!德普之星透视免费(W... 透视手册!德普之星透视免费(WePoKer祈福)一贯真的是有辅助工具(哔哩哔哩)1、德普之星透视免费...
透视窍门!wepoker透视挂... 透视窍门!wepoker透视挂底牌(WePoKer高级)一直真的有辅助脚本(哔哩哔哩)1、wepok...
透视指南!红龙poker辅助(... 透视指南!红龙poker辅助(HHpoker模拟器)竟然存在有辅助神器(哔哩哔哩)1、下载好红龙po...