I have a array of objects, in client side. The object in array look like this:
{
code: 0,
short_name: \'a\',
type: 1
}
I try to
Again, if you are just going to filter
, use the native method instead:
$scope.array1 = data.filter(x => x.type === 1);
$scope.array2 = data.filter(x => x.type !== 1);
You're very close. You just need to change your second filter to:
$scope.array2 = $filter('filter')(data, { type: '!1' });
I also renamed the scope variable since otherwise it would just overwrite your first filtered array.
For me the given solution { type: '!1' }
doesn't work when used with true
as last parameter $filter('filter')(data, {type: 1}, true);
. However using a function works for me (see angular's doc):
$scope.array2 = $filter('filter')(data, function(value, index, array) {
return (value.type !== 1);
}, true);