我的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')}
但是它仅验证第一步描述。所以任何想法如何动态使用索引值?
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 ]*')]),
});