使用嵌套在 ng-repeat 中的 ng-option 进行选择会导致选择列表在 iOS 上出现奇怪的行为。第一次单击添加并从列表中选择一个项目时,选项列表关闭后显示的项目是所选项目下方的项目。如果您检查旁边的必填字段或再次打开选项列表,则会更正显示的项目。这将适用于桌面浏览器,您必须使用 iOS 设备才能看到问题。
<div ng-app>
<div ng-controller="TemplateDetailCtrl">
<button ng-click="addObs()">add</button>
<br/>
<span ng-repeat="obs in template.observations">
<select ng-model="template.observations[$index].observation.id" ng-options="obsOption.id as obsOption.name for obsOption in options | orderBy:'name'">
</select>
<input type="checkbox" ng-model="template.observations[$index].required"/>Required
<button class='btn' ng-click="removeObs($index)">Remove</button>
<br/>
</span>
</div>
</div>
function TemplateDetailCtrl($scope) {
$scope.message = 'Not Ready';
$scope.options = [{id: 1,name: 'Opt1'},{id: 2,name: 'Opt2'},{id: 3,name: 'Opt3'},{id: 4,name: 'Opt4'},
{id: 5,name: 'Opt5'},{id: 6, name: 'Opt6'},{id: 7,name: 'Opt7'},{id: 8,name: 'Opt8'},{id: 9, name: 'Opt9'}];
$scope.template = {};
$scope.addObs = function() {
$scope.message = 'changed...';
if (!$scope.template.observations) {
$scope.template.observations = [];
}
$scope.template.observations.push({
observation: {},
required: 'false'
});
};
$scope.removeObs = function(idx) {
var observations = $scope.template.observations;
observations.splice(idx, 1);
};
}