Want to initialize select with AngularJS and ng-repeat? you can add ng-selected attribute with a condition check logic for the option directive to to make the pre-select work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function AppCtrl($scope) { $scope.filterCondition = { operator: 'neq' } $scope.operators = [{ value: 'eq', displayName: 'equals' }, { value: 'neq', displayName: 'not equal' }] } |
1 2 3 4 5 6 | <body ng-app ng-controller="AppCtrl"> <div>Operator is: {{filterCondition.operator}}</div> <select ng-model="filterCondition.operator"> <option ng-selected="{{operator.value == filterCondition.operator}}" ng-repeat="operator in operators" value="{{operator.value}}">{{operator.displayName}}</option> </select> </body> |
Here is working demo: http://jsfiddle.net/dCFd2/
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.