Angular响应式表单如何向组件传递隐藏字段?
创始人
2024-10-30 07:00:52
0
  1. 在 HTML 表单中添加一个隐藏的表单字段,例如:

  1. 在组件中访问该隐藏字段的值,例如:
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';

@Component({
  selector: 'app-my-form',
  templateUrl: './my-form.component.html',
  styleUrls: ['./my-form.component.css']
})
export class MyFormComponent implements OnInit {
  form: FormGroup;

  constructor(private fb: FormBuilder) { }

  ngOnInit(): void {
    this.form = this.fb.group({
      name: '',
      email: '',
      hiddenField: ''
    });
  }

  onSubmit() {
    const values = this.form.value;
    console.log(values.hiddenField);
  }
}

在上述代码中,我们创建了一个名为 hiddenField 的隐藏字段。在组件的 onSubmit 方法中,我们可以访问该字段的值并将其输出到控制台。

相关内容

热门资讯

透视好友房!wepokerpl... 透视好友房!wepokerplus透视脚本免费,wepoker私人局透视插件(透视)AI教程(有挂方...
透视模拟器!wepoker破解... 透视模拟器!wepoker破解工具,wepoker一直输的号能继续打吗(透视)wpk教程(有挂辅助)...
透视计算!wepoker免费脚... 透视计算!wepoker免费脚本咨询,wepoker透视脚本(透视)黑科技教程(有挂工具)暗藏猫腻,...
辅助透视!wepoker游戏的... 辅助透视!wepoker游戏的安装教程,wepokerplus透视脚本免费(透视)德州论坛(有挂方法...
透视最新!wepoker怎么开... 透视最新!wepoker怎么开辅助,wepoker高级辅助(透视)必赢教程(有挂插件)1)wepok...
透视攻略!wepoker分析,... 透视攻略!wepoker分析,wepoker怎么拿到好牌(透视)存在挂教程(有挂揭秘);1.wepo...
透视挂!wepoker正确养号... 透视挂!wepoker正确养号方法,wepoker是不是有人用挂(透视)安装教程(有挂攻略)1、让任...
透视工具!wepoker有透视... 透视工具!wepoker有透视底牌吗,wepoker手机插件(透视)曝光教程(有挂技巧);1、完成w...
透视透视挂!wepoker透视... 透视透视挂!wepoker透视底牌脚本,wepoker私人局俱乐部辅助(透视)可靠技巧(有挂黑科技)...
透视教学!wepoker免费脚... 透视教学!wepoker免费脚本弱密码,wepoker底牌透视脚本(透视)wpk教程(有挂方法)运w...