For example, I need to apply some CSS rule to one element of collection that is meant to be selected.
<div ng-repeat="fragments" ng-click="makeSelected()"></div>
$scope.fragments = [
{id: 6379, someProperty: "someValue" },
{id: 8934, someProperty: "someValue" },
{id: 1654, someProperty: "someValue" },
{id: 5654, someProperty: "someValue" }
];
$scope.selectedFragmentId = 6379;
The obvious implementation of makeSelected function is to attach a class name selected to div that was clicked then launch a loop through other elements and remove class name selected from them.
Also I need to "select" the particular div without clicking on them, only by passing id of selected fragment in some function. Obviously, this function also must have a loop that will go through fragments and will compare selectedFragmentId with every fragment ids.
My approach looks ok, but I have a bad feeling that it is so imperative instead of declarative. This is not the way in the spirit of angularjs. So, here is a question: is there a way to implement my functionallity in declarative way, without using loops?