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)we... 透视新版(wepoker)wepoker有没有挂(透视)切实真的有挂(德州教程)一、wepoker有...
透视app(WePoKer)w... 透视app(WePoKer)wepoker挂(透视)都是真的有挂(解说技巧)1、操作简单,无需注册,...
透视规律(wepoker)we... 透视规律(wepoker)wepoker怎么增加运气(透视)确实存在有挂(实用技巧);1、这是跨平台...
透视新版(WePoKer)we... 透视新版(WePoKer)wepoker私人局俱乐部(透视)都是真的是有挂(2025新版教程);1、...
透视教程(WePoKer)we... 透视教程(WePoKer)wepoker透视挂底牌(透视)好像是有挂(必赢教程);小薇(透视辅助)致...
透视科技(WEPOKER)we... 透视科技(WEPOKER)wepoker透视破解版(透视)一贯有挂(普及教程);1、wepoker透...
透视教程(wepoker)we... 透视教程(wepoker)wepoker怎么看牌型(透视)一贯存在有挂(AI教程);1)wepoke...
透视系统(WePoKer)we... 透视系统(WePoKer)wejoker私人辅助软件(透视)本来真的是有挂(详细教程)1、上手简单,...
透视好友房(WEPOKER)w... 透视好友房(WEPOKER)wepoker如何设置透视(透视)原来存在有挂(曝光教程)运wepoke...
透视总结(WePoKer)we... 透视总结(WePoKer)wepoker免费脚本咨询(透视)本来是有挂(细节揭秘)1、wepoker...