当使用选项组时,如何使用Angular UI正确初始化Select2标签?

tes*_*123 8 angularjs jquery-select2 angular-ui

我一直试图让我的角度ui select2指令初始化,并且无法让它与选项组一起使用.

代码:

function testCtrl1($scope)
{
    $scope.selectedOptions = ['1'];
    $scope.categories = [
            {label: 'cat1', options: [{desc: 'one', value: 1}]}, 
            {label: 'cat2', options: [{desc: 'two', value: 2}]}
    ];
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

小提琴: 我创造了以下的jsfiddle.

虽然这样做我注意到如果我包含第二个不包含选项组的select2指令(奇怪),它将正确初始化.当我包括第二个select2时,我注意到其他一些奇怪的行为,但我并不太关心它,因为我的目标只是让testCtrl1工作.

Kus*_*han 4

下载最新的 angular-ui select2 并更新第 24 行:

repeatOption = tElm.find( 'optgroup[ng-repeat], optgroup[data-ng-repeat], option[ng-repeat], option[data-ng-repeat]' );
Run Code Online (Sandbox Code Playgroud)

现在它支持选项组。