如何在Angular 6中验证FormArray控件

问题描述 投票:0回答:1

我的HTML看起来像这样-

<form name="add_stepform" [formGroup]="ActionTypeForm" novalidate>
      <cdk-virtual-scroll-viewport [itemSize]="100" class="stepViewPort">
        <div [@fadeInOut] class="TestSteps example-item" *cdkVirtualFor="let step of listOfSteps;TemplateCacheSize:0 let i=index">
          <div formArrayName="steps">
            <div [formGroupName]="i">

步骤说明说明必填

。ts文件-

this.ActionTypeForm = new FormGroup({
  steps: new FormArray([this.testSteps()])})

testSteps() {
return new FormGroup({
  stepDescription: new FormControl('', [Validators.required)}

获取stepDescription(){返回((this.ActionTypeForm.get('steps'))。controls)[0] .get('stepDescription')}

但是它仅验证第一步描述。所以任何想法如何动态使用索引值?

angular validation angular7 angular4-forms formarray
1个回答
0
投票
this.form = new FormGroup({
        Equip_Name: new FormControl('',[Validators.required,  Validators.pattern('^[^]+[a-zA-Z ]*')]),
        Equip_Description: new FormControl('',[Validators.required ,  Validators.pattern('^[^]+[a-zA-Z0-9 ]*')]),
    });
© www.soinside.com 2019 - 2024. All rights reserved.