0

I have the following relevant bit of code in my html file:

<li ng-repeat="answer in answers | orderBy:'-votes' | filter:filterPlayer ">
    {{getPlayerName(answer.playerKey)}}: {{answer.response}} : {{answer.votes}} Votes
</li>

And the following bit of code in my Controller file:

$scope.filterPlayer = function(answer){
  return answer.playerKey !== playerKey;
};

The problem is that the filterPlayer function is not even getting called as I have tested using console.logs and nothing gets logged in the filterPlayer function. I have looked at other stack overflow answers and jsfiddles and this appears to be the proper way to define a custom filter function and use it.

MichaelGofron
  • 1,310
  • 4
  • 15
  • 29
  • I'm just going to suggest a few things but could very well be nothing. First, I don't know how angular handles extra whitespace but I would delete that from the end of `filterPlayer "`. The next thing I'd try would be removing `orderBy` from ng-repeat. After that, I'd have to question if there's any data in `answers` because your code looks right. – Jack Guy Aug 12 '15 at 05:51
  • That's not a filter, that's a function – michelem Aug 12 '15 at 05:52
  • @Michelem you can specify a function attached to the scope as a filter using that syntax. See http://stackoverflow.com/questions/16563018/custom-filters-and-ng-repeat-in-angularjs – Jack Guy Aug 12 '15 at 05:52
  • See the answer at http://stackoverflow.com/questions/16474091/angular-custom-filter-function – thllbrg Aug 12 '15 at 05:53
  • I looked at this stack overflow question previously and this jsfiddle and I don't know what's different between my implementation and theirs: http://stackoverflow.com/questions/11996857/how-to-use-parameters-within-the-filter-in-angularjs – MichaelGofron Aug 12 '15 at 05:53
  • your filter function must return a function – logee Aug 12 '15 at 06:07
  • According to the stack overflow question I linked it isn't necessary. And I tried that as well according to the following: `$scope.filterPlayer = function(){ return function(answer){ return answer.playerKey !== playerKey; }; };` – MichaelGofron Aug 12 '15 at 06:32

1 Answers1

0

Just figured it out. It was a silly bug on my part where I was filtering the results on the wrong page. (I had to filter the players on both pages.) Nothing was wrong with the code.

MichaelGofron
  • 1,310
  • 4
  • 15
  • 29