angularJSfilter不等于

看起来像一个非常基本的问题,但我不能得到正确的语法..

<li class="list-group-item" ng-repeat="question in newSection.Questions | filter:Id != '-1'; " ng-mouseenter="hover = true" ng-mouseleave="hover = false"> <div href="#" editable-text="question.Text">{{question.Text}}</div> </li> 

我只想显示id不是-1的所有问题。 我究竟做错了什么。 谢谢!

语法只是一点点,请尝试:

 <li class="list-group-item" ng-repeat="question in newSection.Questions | filter:{ Id: '!-1'}" ng-mouseenter="hover = true" ng-mouseleave="hover = false"> <div href="#" editable-text="question.Text">{{question.Text}}</div> </li> 

看到一个小JSFiddle: http : //jsfiddle.net/U3pVM/3845/

编辑:

variables示例:

 <script> var invalidId = '-1'; </script> <li class="list-group-item" ng-repeat="question in newSection.Questions | filter:{ Id: '!' + invalidId}" ng-mouseenter="hover = true" ng-mouseleave="hover = false"> <div href="#" editable-text="question.Text">{{question.Text}}</div> </li> 

虽然@迈克尔罗斯答案适用于这种情况下,我不认为这将会如果你试图过滤不等于一些对象/variables

在这种情况下,你可以使用:

JS

 filterId = -1 

HTML:

 <li ng-repeat="question in newSection.Questions | filter: !{ Id: filterId}"> </li> 

一个更嵌套的情况:

JS

 someQuestion = { someObject: { Id: 1 } } newSection.Questions = [someQuestion] 

HTML

 <li ng-repeat="question in newSection.Questions | filter: !{someObject : {Id: -1} }"> </li>