var app = angular.module('myApp', []);
app.controller('listdata', function($scope, $http) {
var data = [{
"name": "John",
"queue": [{
"number": "456",
"status": "Unavailable"
},
{
"number": "111",
"status": "Unavailable"
},
{
"number": "201",
"status": "Paused"
}],
"phone": "7411173737"
},
{
"name": "George",
"queue": [{
"number": "111",
"status": "Paused"
},
{
"number": "456",
"status": "Unavailable"
}],
"phone": "8558855858"
},
{
"name": "Hilary",
"queue": [{
"number": "456",
"status": "Unavailable"
}],
"phone": "5454573737"
},
{
"name": "Edmond",
"queue": [{
"number": "665",
"status": "Unavailable"
}],
"phone": "7454543737"
}];
$scope.a = [];
$scope.users = [];
for(i=0;i<data.length;i++){
for(j=0;j<data[i].queue.length;j++){
if(data[i].queue[j].number == 111 || data[i].queue[j].number == 456){
$scope.a.push(data[i]);
}
}
}
$scope.users = $scope.a;
//console.log($scope.users);
$scope.filter111 = function (user) {
return (user.queue.find(({number}) => number === '111'));
}
$scope.filter456 = function (user) {
return (user.queue.find(({number}) => number === '456'));
}
});
app.filter('unique', function() {
return function(collection, keyname) {
var output = [],
keys = [];
angular.forEach(collection, function(item) {
var key = item[keyname];
if(keys.indexOf(key) === -1) {
keys.push(key);
output.push(item);
}
});
return output;
};
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myApp">
<label class="switch">
<input type="checkbox" ng-model="queue111">111
</label>
<label class="switch">
<input type="checkbox" ng-model="queue456">456
</label>
<label class="switch">
<input type="checkbox" ng-true-value='"Paused"' ng-false-value='' ng-model="paused">Paused
</label>
<div class="row" ng-controller="listdata">
<div ng-repeat="user in users|filter: queue111? filter111: ''|unique:'name'|filter: queue456? filter456: ''|filter: paused track by $index">
<p> {{user.name}} {{user.phone}}</p>
</div>
</div>
</div>
See Question&Answers more detail:
os