我在使用Angular和ng-model在 select2 选择框中预选选项时遇到问题。这是我的代码:
控制器中的角度代码
$scope.filter = {
searchValue: '',
departmentId: 'Department2'
}
HTML
<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>
数据
{
"Department1": [
{
"Name": "Major1",
"Id": 1
},
{
"Name": "Major2",
"Id": 2
},
{
"Name": "Major3",
"Id": 3
}
],
"Department2": [
{
"Name": "Major4",
"Id": 4
},
{
"Name": "Major5",
"Id": 5
},
]
}
据我所知,这适用于 angular-ui-select2 的 0.0.2 版本,但不能高于该版本。我找不到有关如何执行此操作的任何信息。
提前致谢!