mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
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 |
||
|---|---|---|
| .. | ||
| BUILD.bazel | ||
| directives_spec.ts | ||
| form_array_spec.ts | ||
| form_builder_spec.ts | ||
| form_control_spec.ts | ||
| form_group_spec.ts | ||
| reactive_integration_spec.ts | ||
| template_integration_spec.ts | ||
| util.ts | ||
| validators_spec.ts | ||
| value_accessor_integration_spec.ts | ||