I am working with a form group which is defined below:
get createItem(): FormGroup {
return this.formBuilder.group({
name: ['', Validators.required],
email: ['', Validators.required],
mobile: ['', Validators.required],
});
}
This form group is used to generate fields in the following structure:
<form [formGroup]="dynamicFormGroup" (ngSubmit)="onSubmit()">
<div class="row" formArrayName="address" *ngFor="let fields of AddressInfo.controls; let i = index">
<ng-container [formGroupName]="i">
<div class="form-group col-md-12">
<div class="each_content">
<label class="labelTitle">Name <span class="validation-error">*</span></label>
<input type="text" class="form-control height-reset" placeholder="Enter Name" name="name" formControlName="name" />
<div
*ngIf="dynamicFormGroup.get('name').invalid && (dynamicFormGroup.get('name').dirty || dynamicFormGroup.get('name').touched)">
<small class="validation-error">Please provide a title.</small>
</div>
Despite implementing the above code, the validation feature is not working as expected. Could anyone suggest a solution? Thank you.