By default angular uses an empty value if nothing has been selected in a <select>. How can I change this to a text that says Please select one?
Asked
Active
Viewed 8,282 times
7
2 Answers
18
You didnt provide any code so I can't give an example relative to your code, but try adding an option element, e.g.
<select ng-model="item" ng-options="item.category for item in items"
ng-change="doSomething()">
<option value="">Please select one</option>
</select>
Michael Coleman
- 3,288
- 3
- 19
- 18
-
5To add: Having value="" is important. It won't work if you just omit the value attribute. – Vyrx Nov 24 '15 at 17:33
2
Via the ng-selected attribute:
<select>
<option>Hello!</option>
<option ng-selected="selected">Please select one</option>
<option>Another option</option>
</select>
Check out the reference: https://docs.angularjs.org/api/ng/directive/ngSelected
Don
- 506
- 2
- 8
- 23