AngularJS filter exact values with length

Problem

What I want to do is count the filter length of an array of objects by a particular property based on the repeater scope. This code technically works (it displays the correct count of the filter):

<li ng-repeat="question in questions" id="{{ question.id }}">
    {{ question.text }}
    <ul>
        <li ng-repeat="answer in question.answers" id="{{ answer.id }}">
            {{ answer.text }} (<span ng-controller='AnswersController'>{{ (useranswers|filter:{answer_id:answer.id}).length }}</span>)
         </li>
    </ul>
 </li>

The problem is, when scope ID is 1 (for example), it matches on 1,10,11,21, etc. I'd like to make the exact code I have above work on an exact match.

Please let me know what supporting code would be helpful.

Problem courtesy of: Honus Wagner

Solution

You have to say to Angular that you want a strict comparaison. That's easy to do with Angular 1.1.5, because the filter filter (see the documentation) has now a third parameter, comparator, where true is a very usefull shorthand. In your case, you can simply make something like that :

<li ng-repeat="question in questions" id="{{ question.id }}">
    {{ question.text }}
    <ul>
        <li ng-repeat="answer in question.answers" id="{{ answer.id }}">
            {{ answer.text }} (<span ng-controller='AnswersController'>{{ (useranswers|filter:{answer_id:answer.id}:true).length }}</span>)
         </li>
    </ul>
 </li>
Solution courtesy of: Blackhole

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.