angular/packages/forms
Kristiyan Kostadinov ebf2fc5224 fix(forms): incorrectly keeping track of ngModel with ngFor inside a form (#40459)
When an `NgModel` is created within a `form`, it receives an `NgControl` based on its `name`, but
the control doesn't get swapped out if the name changes. This can lead to problems if the `NgModel`
is part of an `ngFor`, because the name can change based on its position in the list and a new
control can be defined with the same name, leading us to having multiple directives pointing to
the same control. For example, if we start off with a list like :

```
[0, 1, 2]; -> [NgModel(0), NgModel(1), NgModel(2)]
```

Then we remove the second item:

```
[0, 2]; -> [NgModel(0), NgModel(2)]
```

And finally, if we decide to add an item to the end of the list, we'll already have a control for
index 2, causing the list to look like:

```
[0, 2, 3]; -> [NgModel(0), NgModel(2), NgModel(2)]
```

These changes fix the issue by removing the old control when the `name` of the directive changes.

Fixes #38465.
Fixes #37920.

PR Close #40459
2022-02-07 13:16:10 -08:00
..
src fix(forms): incorrectly keeping track of ngModel with ngFor inside a form (#40459) 2022-02-07 13:16:10 -08:00
test fix(forms): incorrectly keeping track of ngModel with ngFor inside a form (#40459) 2022-02-07 13:16:10 -08:00
BUILD.bazel ci: add golden files for runtime error codes (#44677) 2022-01-12 20:42:06 +00:00
index.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
package.json refactor(compiler-cli): update peerDependencies to require rxjs ^7.4.0 (#43748) 2021-10-06 15:57:59 -07:00
PACKAGE.md docs: more form overview edits (#25663) 2018-09-25 18:48:15 -07:00
public_api.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00