Skip to content
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
@steven-pribilinskiy

Description

@steven-pribilinskiy

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions