Angular中添加相同值的行。
创始人
2024-10-31 19:00:34
0
  1. 在HTML文件中,使用Angular的“formArrayName”和“formGroupName”指令来表示表单数组和表单组。
  1. 在组件中,先创建一个空的表单数组,然后向其中添加初始的表单组。
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, FormArray } from '@angular/forms';

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

  myForm: FormGroup;

  ngOnInit() {
    this.myForm = new FormGroup({
      myArray: new FormArray([
        new FormGroup({
          myValue: new FormControl('initial value')
        })
      ])
    });
  }

  // 添加新行的方法
  addRow() {
    const control = this.myForm.controls['myArray'];
    const newGroup = new FormGroup({
      myValue: new FormControl('same value')
    });
    control.push(newGroup);
  }
}
  1. 在需要添加新行的地方调用添加新行的方法。

相关内容

热门资讯

了解透视!约局吧德州真的有透视... 了解透视!约局吧德州真的有透视挂吗,微信小程序微乐房间的挂多少钱,讲义教程(有挂透明挂)-哔哩哔哩1...
解谜透视!拱趴大菠萝万能辅助器... 解谜透视!拱趴大菠萝万能辅助器,如何下载微乐自建房免费黑科技,策略教程(有挂解密)-哔哩哔哩1、很好...
教你透视!wejoker辅助器... 教你透视!wejoker辅助器怎么卖,微乐小程序怎么挂脚本,指南教程(有挂秘诀)-哔哩哔哩1、wej...
普及透视!hhpoker德州透... 普及透视!hhpoker德州透视挂,微信小程序四川微乐脚本,方针教程(有挂技巧)-哔哩哔哩1、任何h...
分享透视!hhpoker有没有... 分享透视!hhpoker有没有辅助,微乐a3纸牌有脚本,经验教程(有挂详细)-哔哩哔哩1、完成hhp...
解谜透视!pokemmo手机版... 解谜透视!pokemmo手机版脚本免费,微乐自建房透视,教程书教程(有挂秘籍)-哔哩哔哩1、起透看视...
开挂透视!werplan外卦神... 开挂透视!werplan外卦神器,微乐小程序自建房辅助器下载,方针教程(有挂详细)-哔哩哔哩1、we...
辅助透视!wepoker底牌透... 辅助透视!wepoker底牌透视,微信小程序微乐辅助,妙招教程(有挂秘籍)-哔哩哔哩亲,关键说明,w...
有挂透视!红龙poker辅助器... 有挂透视!红龙poker辅助器免费观看,微乐小程序辅助免费,诀窍教程(确实有挂)-哔哩哔哩1、这是跨...
普及透视!拱趴大菠萝挂,手机微... 普及透视!拱趴大菠萝挂,手机微乐小程序自建房透视免费,攻略教程(果真有挂)-哔哩哔哩1、普及透视!拱...