0
votes

I use AngularJS and bind a <select> to my model:

<select ng-model="model.something" ng-options="..." >
    <option></option>
</select>

It leaves one empty element on top of dropdown, and then generates other options from my view-model.

These things work great:
1. I choose option from dropdown, it is bound to model.something.
2. I choose empty option, model.something is set to null.
3. I set model.something in another function, the correct option is selected.

What does not work:
- I set model.someting to null in another function, empty option is not selected, the previous value is still selected. How to "tell" Angular to select empty option, if I bind model to null value?

1

1 Answers

4
votes

Change <option></option> to <option value=""></option> and set model.someting to empty string "".

UPDATE

Here is a working JSFiddle: http://jsfiddle.net/DianaNassar/6kLW6/