Angular中响应式表单 FormBuilder、FormControl 、FormGroup、FormArray、setControl、setValue用法总结(不定时更新)

以我的项目作为示例,总结一下Angular响应式表单的应用和常用的方法:

1.创建表单

form.ts代码

import { Component, OnInit } from "@angular/core";
import { FormArray, FormBuilder, FormControl, FormGroup, Validators } from "@angular/forms";

@Component({
  selector: "app-form",
  templateUrl: "./form.component.html"
})
export class SLSDetailComponent implements OnInit{

  slsForm: FormGroup;//定义表单slsForm

  ngOnInit(): void {
    
      this.createForm();//初始化创建表单
   
  }

  createForm() {//创建项目需要的数据(多层嵌套的数据)
    
    this.slsForm = this.fb.group({
      UserServiceDescription: this.fb.group({}),
      VPL: this.fb.group({})
    });

  }



}

猜你喜欢

转载自blog.csdn.net/qq_29483485/article/details/84589989
今日推荐