Angular响应式表单显示
创始人
2024-10-30 07:30:26
0

1.在组件中引入FormsModule和ReactiveFormsModule

import { FormsModule, ReactiveFormsModule } from '@angular/forms';
 
@NgModule({
  imports: [
    // other imports ...
    FormsModule,
    ReactiveFormsModule
  ],
})
export class YourModule { }

2.在组件中初始化表单

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
 
@Component({
  selector: 'app-your-component',
  templateUrl: './your-component.component.html',
  styleUrls: ['./your-component.component.css']
})
 
export class YourComponent implements OnInit {
  profileForm = new FormGroup({
    firstName: new FormControl(''),
    lastName: new FormControl('')
  });
 
  ngOnInit() { }
}

3.在HTML中显示表单

4.在组件中处理提交逻辑

onSubmit() {
  // TODO: Use EventEmitter with form value
  console.warn(this.profileForm.value);
}

这样,当用户提交表单时,将会调用onSubmit()方法提交表单的值。 您可以在该方法中将值发送到服务器,或在页面上显示成功消息。

相关内容

热门资讯

出乎意料的是!wepoker私... 出乎意料的是!wepoker私局代打(透视)原来有挂(有挂秘诀开挂辅助安装)-哔哩哔哩1、点击下载安...
围绕透视问题!aapoker辅... 围绕透视问题!aapoker辅助工具安全吗,淘宝买wepoker透视有用吗,操作教程(揭秘有挂)-哔...
为了进一步!pokemmo手机... 为了进一步!pokemmo手机版透视脚本(透视)一直真的是有挂(有挂秘笈开挂辅助工具)-哔哩哔哩1、...
现就发布提示!hhpoker破... 现就发布提示!hhpoker破解工具,wepokerh5破解,手册教程(有挂分享)-哔哩哔哩1、用户...
为切实保障!德普之星的辅助工具... 为切实保障!德普之星的辅助工具介绍(透视)其实确实有挂(讲解有挂开挂辅助安装)-哔哩哔哩1、每一步都...
今天上午!wejoker手机版... 今天上午!wejoker手机版透视脚本,newpoker怎么安装脚本,讲义教程(真是有挂)-哔哩哔哩...
据统计!hhpoker可以开挂... 据统计!hhpoker可以开挂吗(透视)一直真的有挂(有挂详细开挂辅助辅助器)-哔哩哔哩1、上手简单...
刚刚!约局吧德州真的存在透视吗... 刚刚!约局吧德州真的存在透视吗,pokemmo辅助工具,教材教程(今日头条)-哔哩哔哩1、约局吧德州...
据报道!哈糖大菠萝免费辅助器(... 据报道!哈糖大菠萝免费辅助器(透视)原来真的是有挂(有挂教学开挂辅助插件)-哔哩哔哩1、哈糖大菠萝免...
近日!wpk透视辅助下载,we... 近日!wpk透视辅助下载,wepoker透视脚本苹果版,机巧教程(真的有挂)-哔哩哔哩进入游戏-大厅...