Reputation: 36189
I have a list called positions
that has N positions in them. I also have a user user
that has an attribute user.positions
that has some of the positions assigned to.
I want to show a form with all the possible positions, and the positions that the user already has to be checked.
Is this something I can do inside the HTML, or do I need to loop through both in my logic and create a new variable?
Upvotes: 0
Views: 40
Reputation: 3194
<label ng-repeat="position in positions">
<input type="checkbox" ng-checked="user.positions.indexOf(position) != -1" /> {{position}}
</label>
https://docs.angularjs.org/api/ng/directive/ngRepeat
https://docs.angularjs.org/api/ng/directive/ngChecked
Upvotes: 2