Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
feat(forms): formControlName also accepts a number #30606
Please check if your PR fulfills the following requirements:
What kind of change does this PR introduce?
What is the current behavior?
Currently, when using a
<div formArrayName="tags"> <div *ngFor="let tag of tagsArray.controls; index as i"> <input [formControlName]="i"> </div> </div>
This is fine for VE and
What is the new behavior?
This commit relaxes the type of the
Does this PR introduce a breaking change?
This has been discussed with @kara on Slack.
Note that this PR contains two commits:
Also note that no tests were added as the issue is already caught by our tests when
I agree with @alfaproject, there should never be a need* to specify keys in looping a
*: The only exception is to create a sparse Array deliberately, which is really bad practice.
I think we should consider using
<form [formGroup]="myForm" (ngSubmit)="onSubmit()"> <div formArrayName="users"> <div *ngFor="let user of users.controls; index as i"> <div [formGroupName]="i"> <input formControlName="name" placeholder="Name" type="text"/> <input formControlName="age" placeholder="age" type="number"/> </div> </div> </div> </form> <button (click)="addUser()">Add user</button>
If it's OK, I can open an issue or submit my first pull request.