I want to create a filter that only shows items with a matching id, at the moment it only works the other way round. What has to be changed in the function hideIds?
NG
var app = angular.module('m', []);
app.controller('myCtrl', function ($scope) {
$scope.subtree = [{
id: 1,
name: susan
}, {
id: 2,
name: peter
}, {
id: 3,
name: marc
}, {
id: 4,
name: julia
}, {
id: 5,
name: sylvia
}, {
id: 6,
name: martin
}];
var arr = [1,2,6];
$scope.hideIds = function (ids) {
return function (item) {
return arr.indexOf(item.id) === -1;
}
};
});
template
Instead of doing === -1
you can do !== -1
. .indexOf
will return -1
if the array does not contain the element. This means that [1,2,6].indexOf(5)
returns -1
, but [1,2,6].indexOf(1)
returns 0
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments