AngularJS select does not work

2015… Time to wish you happy new year guys! And 2015 is crazy busy. So here comes the first post of the year and it’s a really quick one. Here is your problem: AngularJS select does not work. By does not work I mean is not populating the select box content. And of course, you get no errors in the console. It occurred to me a few days ago and this answer is really easy.

Let’s say you have this code.

<select class="form-control" ng-options="book.id as book.title for book in books"></select>

This might generate a select box but with no options in it and the form-control class is not applied.

###How to fix it? Do not go crazy. The answer is as easy as “funny”. You simply forgot the ng-model attribute.

Without this, select won’t generate.

Here is the right code.

<select class="form-control" ng-model="selectedBook" ng-options="book.id as book.title for book in books"></select>

Lesson learnt!

PS: Don’t forget to initialize selectedBook