我有一个观点

<select ng-model="selected_student" class="form-control">
    <option ng-repeat="obj in students" value="{{obj.id}}">{{obj.name}}</option>
</select>


我在controller中这样做:

$scope.selected_student = $scope.students[0];

为什么它不起作用?

这是我的fiddle

最佳答案

尝试ng-options

 <select ng-model="selected_student" class="form-control" ng-options="student.id as student.name for student in students">


controller中:

$scope.selected_student = $scope.students[0].id;


工作jsfiddle链接:

https://jsfiddle.net/avnesh2/boye4ezk/


将为您工作。

10-07 19:58
查看更多