Check out this Plunker example where a filter is implemented to allow select box options to be selected only once: http://plnkr.co/edit/BBqnTlxobUpiYxfhyJuj?p=preview
.filter('arrayDiff', function() {
return function(array, diff) {
console.log(diff);
var i, item,
newArray = [],
exception = Array.prototype.slice.call(arguments, 2);
for(i = 0; i < array.length; i++) {
item = array[i];
if(diff.indexOf(item) < 0 || exception.indexOf(item) >= 0) {
newArray.push(item);
}
}
return newArray;
};
});
I'm in need of a similar filter, however, my variable diff
is not an array but a number representing the selected value (either 1, 2, 3, or undefined):
In this context, diff
can be either 1,2,[3], or [].
How can I modify the filter to work with a number instead of an array?
Here's how I am currently using the filter: http://plnkr.co/edit/L9hBa5LapAV76wHrwRnX?p=preview