Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Set model to null does not select empty option #8670

Closed
@7c6f1568-555e-42a8-aff6-9045799c8b86

Description

http://plnkr.co/edit/JVMZqnY5Vilek4NxDNGE?p=preview

There is a select like this (nothing unusual here):

 <select ng-model="model.selectedValue"
         ng-options="value.id as value.value for value in modelOptions">
 <option value="" ng-if="!model.selectedValue">Null</option>

Initially the model is null, so when the page first opens the Null option is selected.

$scope.model ={"selectedValue":null};

However, if I then change the selected value to something else, and then back to null by clicking these two buttons

<button ng-click="model.selectedValue=1">Select Yes</button>
<button ng-click="model.selectedValue=null">Select Null</button>

then the Null option is NOT selected - so now the UI is out of sync with the model.

Bug tested with Angular 1.2.22 in IE10 and Chrome 36.

Changing ng-if to ng-show or to ng-if="!$parent.model.selectedValue" fixes the problem in Chrome, but unfortunately in IE10 now I get a different problem - the Null option isn't removed anymore when I select 'Yes'.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions