0

I have this JSON

products: [{
    id: "1",
    model: "123",
    price: "123",
    spec: "213",
    image: "",
    brand: "213",
    category: "1",
    sub_category: "1",
    color: "1",
    size: "1",
    order: "1",
    attributes: [{
        id: "1",
        attribute_id: "1",
        product_id: "1"
    }, {
        id: "2",
        attribute_id: "2",
        product_id: "1"
    }]
}, {
    id: "2",
    model: "456",
    price: "123",
    spec: "213",
    image: "",
    brand: "213",
    category: "1",
    sub_category: "1",
    color: "1",
    size: "1",
    order: "1",
    attributes: []
}]

I am trying to filter the products using ng-repeat

so my ng-repeat is :

<div ng-repeat="product in tv_selections.products | filter: {attributes[0].attribute_id:attribute} | filter:{size:size} | filter:{attribute2:attribute2}" >

I get the selected size and attributes from the controller and its correct

I know my attribute is wrong, but I dont know how I am going to do it, for the other filters its working, on the attributes is not

1
  • 1
    creating a jsfiddle demonstrating your issue would be helpful :)
    – iJade
    Mar 24, 2015 at 11:12

1 Answer 1

0

You can check out the documentation on filters in angular that is on

http://docs.angularjs.org/api/ng/filter/filter

where this code is given ,

    Search: <input ng-model="searchText">
    <table id="searchTextResults">
      <tr><th>Name</th><th>Phone</th></tr>
      <tr ng-repeat="friend in friends | filter:searchText">
        <td>{{friend.name}}</td>
        <td>{{friend.phone}}</td>
      </tr>
    </table>

Angular does on its own, using searchText as reference it will put filter on each property inside the friend object.

Executable code check on this link : http://plnkr.co/edit/MEAHFagGSANOENsaldCC?p=preview

Likewise will be done for your code to search products, check this out , a plunker is created for your answer :

http://plnkr.co/edit/PcF8hfr1ch8BNn2YpxDp?p=preview

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.