我一直试图让我的角度ui select2指令初始化,并且无法让它与选项组一起使用.
代码:
function testCtrl1($scope)
{
$scope.selectedOptions = ['1'];
$scope.categories = [
{label: 'cat1',options: [{desc: 'one',value: 1}]},{label: 'cat2',options: [{desc: 'two',value: 2}]}
];
}
HTML:
<select multiple ui-select2 ng-model="selectedOptions" style="width: 300px">
<optgroup ng-repeat="category in categories" label="{{category.label}}">
<option ng-repeat="option in category.options" value="{{option.value}}">{{option.desc}} - {{option.value}}</option>
</optgroup>
</select>
小提琴:
我创建了以下jsfiddle.
虽然这样做,但我注意到如果我包含第二个不包含选项组的select2指令(奇怪),它将正确初始化.当我包括第二个select2时,我注意到其他一些奇怪的行为,但我并不太关心它,因为我的目标只是让testCtrl1工作.
下载最新的angular-ui select2并更新第24行:
repeatOption = tElm.find( 'optgroup[ng-repeat],optgroup[data-ng-repeat],option[ng-repeat],option[data-ng-repeat]' );
现在它支持选项组.