angular/packages/forms/src
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
..
directives fix(forms): incorrectly keeping track of ngModel with ngFor inside a form (#40459) 2022-02-07 13:16:10 -08:00
directives.ts perf(forms): make RadioControlRegistry class tree-shakable (#41126) 2021-03-16 09:35:14 -07:00
errors.ts refactor(forms): use shared RuntimeError class (#44398) 2022-01-06 23:43:19 +00:00
form_builder.ts refactor(forms): use shared RuntimeError class (#44398) 2022-01-06 23:43:19 +00:00
form_providers.ts perf(forms): make RadioControlRegistry class tree-shakable (#41126) 2021-03-16 09:35:14 -07:00
forms.ts refactor(forms): Move FormControl to an overridden exported constructor. (#44316) (#44806) 2022-01-31 22:48:23 +00:00
model.ts refactor(forms): Move FormControl to an overridden exported constructor. (#44316) (#44806) 2022-01-31 22:48:23 +00:00
validators.ts fix(forms): Correct empty validator to handle objects with a property length: 0. (#33729) 2022-02-03 23:15:27 -08:00
version.ts docs: fix package name in version.ts files in different packages (#41208) 2021-05-10 10:26:34 -04:00