Angular JS filter not equals

后端 未结 2 815
臣服心动
臣服心动 2020-12-08 12:45

Seems like a very basic question but I can\'t get the syntax right..

  • 相关标签:
    2条回答
    • 2020-12-08 13:12

      Although @Michael Rose answer works for this case, i don't think it will if you try to filter not equal some object/variable

      In that case you could use:

      JS:

      filterId = -1
      

      HTML:

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

      An even more nested case:

      JS:

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

      HTML

      <li ng-repeat="question in newSection.Questions | filter: !{someObject : {Id: -1} }">
      </li>
      
      0 讨论(0)
    • 2020-12-08 13:25

      The syntax is just a little off, try:

      <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>
      

      See a little JSFiddle: http://jsfiddle.net/U3pVM/3845/

      Edit:

      Example with 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>
      
      0 讨论(0)
    提交回复
    热议问题