I love AngularJS. The official Angular documentation, however, can be quite frustrating.
One of the more poorly explained concepts in the Angular docs is the ng-options (ngOptions) parameter of the select directive.
While I was building a Settings page the other day, I stumbled upon an undocumented "comprehension expression" that works very nicely for certain use-cases:
key as value for (key, value) in options
This allows you to then create a quick and dirty object for your options and use the keys for your values:
$scope.options = new Object(); $scope.options = 'No'; $scope.options = 'Yes';
This gives you a reusable object to iterate your Yes/No/Whatever select boxes with and works perfectly when you are storing your options as ints in your database.
<select ng-model="settings.weekly_email" ng-options="key as value for (key, value) in options"></select> <select ng-model="settings.push_notifications" ng-options="key as value for (key, value) in options"></select>
Your models will select the correct value right off the bat - without having to define the initial value in the controller to avoid the dreaded blank select box value.