Reputation: 931
I have a view
<select ng-model="selected_student" class="form-control">
<option ng-repeat="obj in students" value="{{obj.id}}">{{obj.name}}</option>
</select>
I am doing this in controller
:
$scope.selected_student = $scope.students[0];
why it doesn't work?
Here's my fiddle
Upvotes: 1
Views: 60
Reputation: 3906
Try ng-options
:
<select ng-model="selected_student" class="form-control" ng-options="student.id as student.name for student in students">
And in controller
:
$scope.selected_student = $scope.students[0].id;
Working jsfiddle link:
https://jsfiddle.net/avnesh2/boye4ezk/
Will work for you.
Upvotes: 1