1

I have a filter in my controller like this:

$scope.LegEntQueue = $filter('filter')(legEncoderQueue, {FileAppCD: 'ENT'}).length;

Where I am counting the results of an array called legEncoderQueue based on a property called FileAppCD if it has the value of ENT

This works perfectly, but is there a way to have it fuzzy search and select anything that has ENT in the value? Such as ENT-M-And and ENT-M-iOS?

1
  • you could to .filter over collection with your own code condition(regex) plain javascript.. Commented Oct 20, 2016 at 17:06

2 Answers 2

2

There's a property $ that will perform a substring search of all your properties within your collection. In your case, you can use

$scope.LegEntQueue = $filter('filter')(legEncoderQueue, {$: 'ENT'})

From the angular docs

A special property name ($ by default) can be used (e.g. as in {$: "text"}) to accept a match against any property of the object or its nested object properties.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry I didn't word that right, I want to select all objects with {FileAppCD: 'ENT'} or {FileAppCD: 'ENT-M-And'} or {FileAppCD: 'ENT-M-iOS'} and so on. I have like 15 different FileAppCD values that start with ENT and I'd like to select them all in one go, instead of writing 15 separate filter statements.
@Greyhammer I'd suggest specifying a filter function and use a regular expression or any custom logic if you need more control.
0

Thank you all for your input, it took me a moment to realize my ignorance, thinking I could just use some built in angular filter to do what just plain javascript could do.

My Solution, was to create a function:

$scope.regexCount = function(array, feild, pattern) {
    var count = 0;
    for (index = 0; index < array.length; index++) {
        if (pattern.test(array[index][feild])) {
            count ++;
        }
    }
    return count;
};

And then pass in my parameters.

$scope.LegEntQueue = $scope.regexCount(legEncoderQueue, 'FileAppCD', /ENT.*/);

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.