0

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

3
  • 1
    Each iteration of ng-repeat creates its own (child) scope. Therefore, ng-mode="skill" will create a skill primitive property on the child scope, not on the scope where character is defined. See stackoverflow.com/questions/14049480/… (section ng-repeat) for some ideas. Commented Apr 5, 2013 at 17:06
  • great artikle, thanks for pointing this out. what I don't get is, that in my case, skills are objects, and not primitives. so shouldn't the skill in the ngrepeat reference the character skill..? Commented Apr 6, 2013 at 7:10
  • Sorry, I didn't realize each skill is an object. (It would be helpful to include some more code next time.) Commented Apr 6, 2013 at 16:01

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.