roemer
roemer

Reputation: 537

angular js array of objects for select with ngOptions

I have a character which can contain multiple skills. Skills are available from an injected service. What I basically want is this:

<div ng-repeat="skill in character.getSkills()">
    <select ng-model="skill" ng-options="select as s.toString() for s in getAllSkills()"></select>
    <button ng-click="character.removeSkill(skill)" >Remove Skill</button>
</div>

With this code, the select box doesn't work as I would expect it. Skills are not set in the character, and selections are not kept in the drop down.

Am I missing something?

Thanks in advance, roemer

Upvotes: 0

Views: 2475

Answers (1)

roemer
roemer

Reputation: 537

After all, I'm referencing the skill in the character.skills array by the $index property in the child scope:

<select ng-model="character.skills[$index]" ng-options="sk as sk.toString() for sk in getAllSkills()"></select>

Upvotes: 1

Related Questions