I have several arbitrary number of menu items on my page. Simplified they look like this.
<a href="" class="menu-item" ng-click="...">...</a>
I would like to add a particular class to an item that is being clicked so that its state changes compared to others.
I know I should do it sugin this kind of a pattern:
<a href=""
class="menu-item"
ng-class="{ active: clicked }"
ng-click="clicked = true">
...</a>
but the problem is that I can't use a single variable as I have an arbitrary number of items. I should either use X number of variables or use an array. But in any case how would I know which item goes with each variable/array index unless I manually enter those indices by hand?
What I'm missing
I'm missing element reference that I could use in ng-click so I could add a particular class on element itself. But that would somewhat bind $scope and UI even though I wouldn't be using any $scope function that would manipulate UI. I'd do it all in the view...
How am I supposed to do this?
ng-repeat? How do you generate your "arbitrary number of items" ?ng-repeatI know I could use$indexin such case. I have several page sections where these item reside and number of them changes according to routing view. Some are always present others are loaded as perng-view.