Situation:
I work with angular.js for frontend (newbie) and with symfony2 (php) for backend. I query for a list of users and groups. So the html could look like that.
<ul class="user-list">
<li ng-repeat="user in users">
<a ng:click="select(user)">
{{user.first_name}} {{user.last_name}}
</a>
</li>
</ul>
<div class="user-was-selected" ng-show="selectedUser != null">
<ul class="dropdown-menu">
<li ng-repeat="group in groups"><a>{{ group.name }}</a></li>
</ul>
</div>
When a user is selected from the list another view will be shown that displays a dropdown list filled with groups. This are all groups available. So the list query does not depend on the user.
However a user can be a member of a group. So I need to set a class on the li element, like "in-group".
In symfony2 this is easy, because its templating engine "twig" has methods like user.hasGroup to check if the user is in the group. I can do this right in the twig template.
My question is, do I have to make a rest api call for this? It would mean I have to make a rest api group check per group for every user. Does this make any sense or do you see another solution?
In addition to that, a click on a group from the dropdown would remove/add (toggle) the user from the clicked group.