Search code examples
c#angularjsng-options

Binding Select Option to Model AngularJS


After debugging it seems that the status object is getting bound to my model. But I need to bind the string to my model.

$scope.Statuses = [
    {name:'Not Started', value: 'Not Started'},
    {name:'In Progress', value: 'In Progress'},
    {name:'Completed', value: 'Completed'}
];

<select class="form-control" ng-model="counterMeasure.Status" ng-options="status.name for status in Statuses"></select>

Solution

  • You need to use following ngOptions syntax

    select as label for value in array

    Change your code to

    ng-options="status.value as status.name for status in Statuses"