This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Pre-select an option in ng-options optgroup (with "group by" property) #12966
Closed
Description
I need to pre-select an <option>
in a dropdown that has option groups.
Without <optgroup>
the ng-model
reads the value and selects the right option, somewhy that doesn't work with option groups.
Giving a simple example:
<select
ng-model="selected"
ng-options="option.value group by option.type for option in options"
></select>
$scope.options = [
{type:'Mini', value:'Option 1'},
{type:'Mini', value:'Option 2'},
];
//$scope.selected = 'Option 2';
$scope.selected = {type:'Mini', value:'Option 2'};
and a sandbox
http://plnkr.co/edit/1AZ3VosOhfYkj1fImbwv?p=preview