我在选择框中使用了ng-repeat,它显示了所有选项,一旦我选择了任何选项,那么所有选项都会闪存,无法理解为什么会发生这些选择
<select name="medical_specialty" ng-model="medical_specialty" class="form-control" ng-if="medical_specialty">
<option value="">All Specialties</option>
<option ng-repeat ="medical_s in medical_specialty track by $index" value="{{medical_s.id}}">{{medical_s.name}}</option>
</select>
首次加载时的前视图,我无法理解为什么? object:300 ?
选择任何选项后,所有选项都会获得闪存
答案 0 :(得分:1)
您应该使用ng-options
来显示选择而不是<option>
标记的ng-repeat中的选项。
ng-options的一个例子是
<select ng-options="user.name for user in users track by user.id" ng-model="selectedUser"></select>
在您的情况下,请尝试
<select name="medical_specialty" ng-model="medicalSpecialty" ng-options=""medical_s.name for medical_s in medical_specialty track by $index">
详细了解
ng-options
here&#13;&#13;&#13;&#13;&#13;angular.module('Demo', []).controller('DemoCtrl', function($scope) { $scope.users = [{ id: 1, name: 'John' }, { id: 2, name: 'Doe' }]; });
&#13;<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <body ng-app="Demo"> <div ng-controller="DemoCtrl"> <select ng-options="user.name for user in users track by user.id" ng-model="selectedUser"></select> <div> Selected User: {{selectedUser}} </div> </div> </body>