Two ng-select elements bound to same form control are not in sync
Describe the bug Given two ng-select elements that are both bound to the same form control (reactive forms) when the user selects an item in one of the ng-select elements then I expect the second ng-select element to be updated accordingly.
Reproducbile example https://stackblitz.com/edit/angular-894pxt
To Reproduce Steps to reproduce the behavior (if example is not provided):
- Select entry in first ng-select
- Second ng-select is not updated
Expected behavior Second ng-select shows the same selected entry.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions :fireworks:
No solution for this yet, had to work around it by patching the value to the formControl manually in a change event. Really annoying, but oh well.
It works as expected, you can confirm that replacing it with simple selects and you will get identical behaviour:
<select
(ngModelChange)="showConfirm(confirmation)"
placeholder="Select age"
formControlName="age">
<option *ngFor="let age of ages" [value]="age.value">{{ age.label }}</option>
</select>
<select
(ngModelChange)="showConfirm(confirmation)"
placeholder="Select age"
formControlName="age">
<option *ngFor="let age of ages" [value]="age.value">{{ age.label }}</option>
</select>
AFAIK, you can't have controls with the same formControlName. Please refer to StackOverflow to solve your problem.