1

Say I have the following formGroup structure:

userGroup = {
   name,
   surname,
   address: {
      firstLine,
      secondLine
   }
}

This forces me to write HTML similar to the following:

<form [formGroup]="userGroup">
   <input formControlName="name">
   <input formControlName="surname">

   <div formGroupName="address">
      <input formControlName="firstLine">
      <input formControlName="secondLine">
   </div>
</form>

Let's say, just for the sake of the example, that you are constrained to write HTML that looks like this:

<form [formGroup]="userGroup">
   <input formControlName="name">
   <input formControlName="surname">

   <div formGroupName="address">
      <input formControlName="firstLine">
   </div>

   <hr>
   <div formGroupName="someOtherGroup">
       <input id="problemSecondLine" formControlName="???.secondLine">
  </div>
</form>

Is there a way, to force the field with id=problemSecondLine to be under userGroup -> address -> secondLine, even though, visually, I have no option but to place it under this particular DIV?

I guess I can manually update via ngModel - but I'm trying to find the cleanest way possible.

1 Answer 1

1

You can use formControl directive instead of formControlName

<input id="problemSecondLine" [formControl]="userGroup.get('address.secondLine')">

Plunker Example

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.