Angular chosen multiple with default values

265 Views Asked by At

HTML:

       <select chosen multiple class="form-control" ng-model="model.Skills"
          ng-options="skills.name.skillName for skills in skills" 
data-placeholder="Select Skills" >
          <option value=""></option>
        </select>

$scope.skills = [
  {
    "skillName": "C",
    "idx": "0"
  },
  {
    "skillName": "C++",
    "idx": "1"
  },
  {
    "skillName": "Java",
    "idx": "2"
  }
]

idx is index of the skills . My angular chosen does multi selection. I wanted to set my default value as Java and C so I set it as following

$scope.model = {};

$scope.model.Skills = [2,1];

$scope.selected = 2;

but its not working out. https://plnkr.co/edit/cQEB5T?p=preview I used following example.

1

There are 1 best solutions below

0
On

Change your code according to this code snippet...

<select
   chosen multiple
   ng-model="model.Skills"
   ng-options="s.idx as s.skillName for s in skills ">
   <option value=""></option>
</select>