1

My filter should return items in object when elements of object exists in array:

$scope.isCategory = function() {
    return function(item) {
        if($scope.filterObj.categories.length > 0) {
            return angular.forEach( $scope.filterObj.categories, function(value, key) {
                return (item.categories.indexOf(value) == -1);
            });
        }
        return item;
    }
};

Where $scope.filterObj is ["a", "b"] and item.categories is ["a"].

1
  • Does it work for you? Commented Mar 13, 2017 at 15:07

1 Answer 1

1

Try:

$scope.isCategory = function() {
    return function(item) {
        if($scope.filterObj.categories.length > 0) {
            var found = false;
            angular.forEach($scope.filterObj.categories, function(value, key) {
                if (!found && item.categories.indexOf(value) !== -1) {
                    found = true;
                }
            });

            return found ? item : null;
        }
        return item;
    }
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.