ng-repeat :filter by single field

后端 未结 12 2101
栀梦
栀梦 2020-11-22 10:06

I have an array of products that I\'m repeating over using ng-repeat and am using

<
相关标签:
12条回答
  • 2020-11-22 11:00

    Specify the property (i.e. colour) where you want the filter to be applied:

    <div ng-repeat="product in products | filter:{ colour: by_colour }">
    
    0 讨论(0)
  • 2020-11-22 11:00

    my way is this

    subjcts is
    
    [{"id":"1","title":"GFATM"},{"id":"2","title":"Court Case"},{"id":"3","title":"Renewal\/Validity"},{"id":"4","title":"Change of Details"},{"id":"5","title":"Student Query"},{"id":"6","title":"Complains"}]
    

    sub is a Input field or whatever you like

    Displaying like this

    <div ng-if="x.id === sub" ng-repeat=" x in subjcts">{{x.title}}</div>
    
    0 讨论(0)
  • 2020-11-22 11:00

    If you want filter for one field:

    label>Any: <input ng-model="search.color"></label> <br>
    <tr ng-repeat="friendObj in friends | filter:search:strict">
    

    If you want filter for all field:

     label>Any: <input ng-model="search.$"></label> <br>
     <tr ng-repeat="friendObj in friends | filter:search:strict">
    

    and https://docs.angularjs.org/api/ng/filter/filter good for you

    0 讨论(0)
  • 2020-11-22 11:02

    Specify the property in filter, of object on which you want to apply filter:

    //Suppose Object
    var users = [{
      "firstname": "XYZ",
      "lastname": "ABC",
      "Address": "HOUSE NO-1, Example Street, Example Town"
    },
    {
      "firstname": "QWE",
      "lastname": "YUIKJH",
      "Address": "HOUSE NO-11, Example Street1, Example Town1"
    }]
    

    But you want to apply filter only on firstname

    <input type = "text" ng-model = "first_name_model"/>
    <div ng-repeat="user in users| filter:{ firstname: first_name_model}">
    
    0 讨论(0)
  • 2020-11-22 11:05

    See the example on the filter page. Use an object, and set the color in the color property:

    Search by color: <input type="text" ng-model="search.color">
    <div ng-repeat="product in products | filter:search"> 
    
    0 讨论(0)
  • 2020-11-22 11:05

    If you were to do the following:

    <li class="active-item" ng-repeat="item in mc.pageData.items | filter: { itemTypeId: 2, itemStatus: 1 } | orderBy : 'listIndex'"
                    id="{{item.id}}">
        <span class="item-title">{{preference.itemTitle}}</span>
    </li>
    

    ...you would not only get items of itemTypeId 2 and itemStatus 1, but you would also get items with itemType 20, 22, 202, 123 and itemStatus 10, 11, 101, 123. This is because the filter: {...} syntax works like a string contains query.

    However, if you were to add the : true condition, it would do filter by exact match:

    <li class="active-item" ng-repeat="item in mc.pageData.items | filter: { itemTypeId: 2, itemStatus: 1 } : true | orderBy : 'listIndex'"
                    id="{{item.id}}">
        <span class="item-title">{{preference.itemTitle}}</span>
    </li>
    
    0 讨论(0)
提交回复
热议问题