Angular JS filter equals

Footabll.My.Life picture Footabll.My.Life · Nov 14, 2014 · Viewed 15.3k times · Source

Please see the details. Why is the output wrong?

HTML:

<div ng-app>
    <div ng-controller="TodoCtrl">
         <h1>List</h1>

        <div ng-repeat="t in todos | filter:{ id: '-1'}">{{t.text}}</div>
    </div>
</div>

Angular code:

function TodoCtrl($scope) {
    $scope.todos = [{
        text: 'learn angular',
        done: true,
        id: -1
    },{
        text: 'learn angular 2',
        done: true,
        id: -11
    }, {
        text: 'build an angular app',
        done: false,
        id: 1
    }];
}

Output:

learn angular
learn angular 2

Please see:

filter:{ id: '-1'}

Why does the output include:

learn angular 2

I want to search the id -1, but learn angular 2 is -11

Answer

Ankur Agarwal picture Ankur Agarwal · Nov 14, 2014

Remove the quotes from '-1' and send true to the filter to do a strict comparison.

ng-repeat="t in todos | filter:{ id: -1}:true"