I'm struggling with setting a default option in a select2 dropdown using Angular and an ng-model. Here's my implementation:
Angular controller code snippet
$scope.filter = {
searchValue: '',
departmentId: 'Department2'
}
HTML markup
<select
class="form-control"
ui-select2="{allowClear: true}"
ng-model="filter.departmentId">
<option value=""></option>
<option ng-repeat="(department, majors) in departments" value="{{department}}">{{department}}</option>
</select>
Data structure
{
"Department1": [
{
"Name": "Major1",
"Id": 1
},
{
"Name": "Major2",
"Id": 2
},
{
"Name": "Major3",
"Id": 3
}
],
"Department2": [
{
"Name": "Major4",
"Id": 4
},
{
"Name": "Major5",
"Id": 5
},
]
}
It appears that this functionality worked in version 0.0.2 of angular-ui-select2 but not beyond that version. I haven't been able to find any documentation on how to achieve this.
Any help would be much appreciated!