My challenge is to have a pre-filled option in a select-box using ng-repeat with AngularJS 1.1.5. However, the select box always starts off with nothing selected and an empty option, which I don't want. It seems to be a side effect of not having anything selected initially.
I have managed to make it work by using ng-options instead of ng-repeat, but I prefer to use ng-repeat in this scenario. Even though my simplified example may not show it, I also need to set the title attribute for each option, which cannot be achieved with ng-options as far as I am aware.
I don't believe this issue is related to the common AngularJS scope/prototypical inheritance problem. I haven't noticed anything obvious when inspecting in Batarang. Additionally, when an option is manually selected in the UI, the model updates correctly.
Here's the HTML snippet:
<body ng-app ng-controller="AppCtrl">
<div>
Operator is: {{filterCondition.operator}}
</div>
<select ng-model="filterCondition.operator">
<option
ng-repeat="operator in operators"
value="{{operator.value}}"
>
{{operator.displayName}}
</option>
</select>
</body>
And here is the corresponding JavaScript code:
function AppCtrl($scope) {
$scope.filterCondition={
operator: 'eq'
}
$scope.operators = [
{value: 'eq', displayName: 'equals'},
{value: 'neq', displayName: 'not equal'}
]
}
You can view the JS Fiddle for this here.