Search code examples
javascriptcssangularjsangularjs-ng-repeatng-class

Selecting all NG-Repeat iterations except the selected one


Is there a way to do a jQuery like selection of a particular iteration of an ng-repeat?

When editing a particular article I want all the other articles to be faded out so I'm using a function:

ng-click="edit(articleKey)"

And will be using ng-class to do the specified fading.

How would I go about making the function in the controller have this behaviour?


Solution

  • You can use $index to do that.

    Something like this.

      <ion-list>
            <ion-item ng-click="selected.value = $index" ng-repeat="item in items" ng-hide="selected.value === $index">
               Hello, {{item}}!
            </ion-item>
      </ion-list>
    

    Just store the selected value when clicked and instead of ng-hide you can use ng-class to fade out the elements, comparing them to the selected index.