Nicoleta Wilskon Nicoleta Wilskon - 1 month ago 5
JSON Question

Angular filter on object key in response

I have Json request as below. I need to filter only values from key with

intrsted
in table.I am new to filters and handling key in angular. I attached my JSON request and response, need assistane.

JSON:

var customer =
[
[
{
"businessuserid": 44,
"businessusername": "rk business New",
"businessusermobile": "00",
"businessusercountrycode": "91",
"admin": true,
"mobilevalidated": false,
"emailvalidated": false,
"email": "riteshnew@gmail.com",
"upin": "000044"
}
],
[
{
"approved": true,
"businessuserid": 43,
"businessusername": "Cakey Bakes",
"businessusermobile": "8050663763",
"businessusercountrycode": "91",
"admin": true,
"mobilevalidated": true,
"emailvalidated": false,
"email": "preethi@groupz.com",
"upin": "000043"
}
],
[
{
"intrsted": true,
"attended": false,
"businessuserid": 44,
"businessusername": "rk business New",
"businessusermobile": "00",
"businessusercountrycode": "91",
"admin": true,
"mobilevalidated": false,
"emailvalidated": false,
"email": "riteshnew@gmail.com",
"upin": "000044"
}
],
[
{
"intrsted": true,
"attended": false,
"businessuserid": 52,
"businessusername": "Cars workshop",
"businessusermobile": "9535000636",
"businessusercountrycode": "91",
"admin": true,
"mobilevalidated": true,
"emailvalidated": false,
"email": "preethi@car.com",
"upin": "000052"
}
]


Html:

<table ng-repeat="item in customers | filter: { intrsted: true }">
<td>{{item.businessusername}}</td>
<tr>
</table>

Answer

There is nothing wrong with your filter usage. Problem is at your ng-repeat usage. If you double check your json object you will see your every item is another array so you need to use inner object as array. Fix your html like this

<table ng-repeat="item in customers | filter: { intrsted: true }">
    <td>{{item[0].businessusername}}</td>
</table>

You see your item is just an another array so use it like item[0] and you will get the result you want...

UPDATE

for showing inner array list on html use second ng-repeat inside of first ng-repeat...

<table ng-repeat="item in customers | filter: { intrsted: true }">
    <td ng-repeat="customer in item">{{customer.businessusername}}</td>
</table>
Comments