1

This is my form object

 this.userFormGroup = this.fb.group({
            name : ["", Validators.required],
            email : "",
            phone : ""
            address : this.fb.group({
                city : ["", Validators.required],
                state : ""
            }),
            hobbies : this.fb.array([
                this.fb.group({
                    name : ["", Validators.required]
                }),
            ])
        })

I have used this object in the below mentioned HTML.

<div formArrayName="hobbies">
                <div formGroupName="0">
                    Name <input type="text" formControlN!ame="name">  <br><br>
                    <div *ngIf="userFormGroup.get('hobbies[0].city').hasError('required')">
                        City Required
                    </div>
                </div>
            </div>

Other validations are working but form validations are not working.

Thanks in advance.

1 Answer 1

3

Try this

<div *ngIf="userFormGroup.get('hobbies').controls[i].get('name').errors">
     City Required
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.