Select with ng-option nested in a ng-repeat causes select list to have odd behavior on iOS. The first time you click add and select an item from the list the displayed item after the option list closes is the item below the one selected. If you check the required field next to or open the option list again the item displayed is corrected. This will work on desktop browser you must use iOS device to see the issue.
<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);
};
}
I'll guess it might have something to do with the following Angular operation:
When the list displays initially, Angular will have added an option like this to the HTML,
<option value="?" selected="selected"></option>
since $scope.template.observations[$index].observation.id is not initially set to a valid option/value:
After selecting a valid choice, that option will magically disappear, and maybe that is confusing iOS somehow...
See if adding this one option helps (it prevents that special option from being generated):
<select ng-model="template.observations[$index].observation.id" ng-options="obsOption.id as obsOption.name for obsOption in options | orderBy:'name'">
<option style="display:none" value=""></option>
</select>