Populating Selects

http://angularjs.org/

by zdam

HTML

<div ng-controller="MyCtrl">
    Works as expected:
    <select ng-model='form.working' required ng-options='option as option.name for option in dropDownOptions'></select>
    
    I would like this to work as well!:
    <select ng-model='form.notWorking' required ng-options='option as option.name for option in dropDownOptions'></select>
    
    <hr/>    
    Debug:<br/>
    {{form.notWorking}}
</div>

JavaScript

var myApp = angular.module('myApp',[]);


function MyCtrl($scope) {
    
    $scope.dropDownOptions = [
    { name: 'Feature', value: 'feature' }, 
    { name: 'Bug', value: 'bug' }, 
    { name: 'Enhancement', value: 'enhancement' }
    ];
    
    $scope.form = {
        
        // Works by directly referencing an item in the dropDownOptions
        working : $scope.dropDownOptions[0],
        
        // Doesn't work - value equality is no good, it appears only reference equality works.
        notWorking : { name: 'Feature', value: 'feature' }         

    };
    
}