10

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

1 Answer 1

25

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"

Sign up to request clarification or add additional context in comments.

3 Comments

Why does this happen?
what if i want not equal to -1 values with :true ??
can you help for this http://jsfiddle.net/U3pVM/33383/ , why last one is not display in output , event there is id is -12 ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.