3

I have some JSON data that is rendered out via the ng-repeat directive, and the results are then filtered via some checkboxes/drop-downs, and some custom filter functions in my controller.

I now want to add a function to my controller that is triggered by an 'ng-change' on some of the checkboxes, that can reference the current list of items in my 'ng-repeat'. I realise I can reference these values from a custom filter, for example $scope.filterProvider = function(item), but this function is then called for each and every item in the ng-repeat, which isn't what I want - I want the function to just be called each time a checkbox is checked/unchecked, and I need that function to be able to reference the items in my ng-repeat...does that make sense to anyone?! And if so, does anyone know how I can do that?

Thanks :-)

John Slegers
  • 45,213
  • 22
  • 199
  • 169
ParkerDigital
  • 1,015
  • 3
  • 12
  • 16
  • 1
    Bit of a head scratcher that one, but apparently you can do this: http://stackoverflow.com/questions/11721863/angularjs-how-to-get-an-ngrepeat-filtered-result-reference – willmcc May 28 '13 at 14:09
  • Cheers, that's exactly what I'm trying to do - that works a treat :-) – ParkerDigital May 28 '13 at 14:21

1 Answers1

2

Say you have ng-repeat="item in items", then you may use something like ng-click=thisAmazingFct(item) that will pass the current item while calling thisAmazingFct.

If you prefer using the index of the item in the items array, use something like ng-click=thisAmazingFctByIndex($index) where $index is automatically set to the current item index by angular with the ng-repeat directive.

ocolot
  • 718
  • 6
  • 18