How to apply a NOT filter in the following example?
Tried $filter('filter')(users,{ranks: {id: '!' + '15'},true) and $filter('filter')(users, !{ranks: {id:15}},true) but nothing seems to work.
The aim here is to not get user with id = 15 in the filtered array
Controller:
app.controller('MainCtrl', function($scope,$filter) {
$scope.users = [
{
id: 1,
name: 'John Doe',
ranks: [
{ id: 1, name: 'Admin'},
{ id: 2, name: 'Doe' }
],
},
{
id: 2,
name: 'Barbara Doe',
ranks: [ { id: 15, name: 'Wife'}, { id: 2, name: 'Doe' }],
},
{
id: 3,
name: 'Jane Doe',
ranks: [ { id: 16, name: 'Wife'}, { id: 17, name: 'Doe' }],
},
];
$scope.filter = $filter('filter')($scope.users, {ranks: {id: !15}},true);
});
HTML:
<p>HTML Filter: List of users without having a rank with id: 15</p>
<ul>
<li ng-repeat="user in users | filter:{ranks: {id: '!' + '15'}} : true">
{{ user }}
</li>
</ul>
<p>Controller Filter: List of users without having a rank with id: 15</p>
<ul>
<li ng-repeat="user in filter ">
{{ user }}
</li>
</ul>
Plunker: http://plnkr.co/edit/73lLDpn3uLHozObKn539?p=preview