I have a very basic select-option input control in Angular 8. User selects one item from dropdown and it's reflected correctly in dropdown as well as in ngModel variable.
But if I empty the source array programmatically, dropdown is still keeping the old value in ngModel and angular validation shows the control to be in a "valid" state. However, nothing is shown as selected in the dropdown as the source array is now empty.
I am expecting that ngModel should be reset and control should be in invalid state as nothing is selected now.
Is my expectation wrong? Or am I doing something wrong?
Following is a complete example to reproduce the behavior:
Angular 8: StackBlitz
Update 1:
I have created an example in Angular 1 which is working exactly as I expected. AngularJS clears the model value if there is no matching option found in options array. My point is that if dropdown is visible empty then user would assume nothing is selected. However in case of Angular2+, its holding old model value behind the scene.
Angular 1: StackBlitz