Like most things in Angular.js, once you know how to do it, it’s really simple. This time I was struggling with creating a dropdown in Angular.js and providing it with an extra default ‘select a category…’ option.
This is how I got this working:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select ng-options="category.id as category.name for category in categories" ng-model="category"> | |
<option value="">select a category...</option> | |
</select> |
The only thing I had to do was adding one extra <option> tag myself inside the <select>. Easy enough once you know it!