AngularJS filter for multiple strings

angularjs

Solution

Please see surfbuds answer below as it is superior

Just roll with your own filter:

.filter("myFilter", function(){
    return function(input, searchText){
        var returnArray = [];
        var searchTextSplit = searchText.toLowerCase().split(' ');
        for(var x = 0; x < input.length; x++){
            var count = 0;
            for(var y = 0; y < searchTextSplit.length; y++){
                if(input[x].toLowerCase().indexOf(searchTextSplit[y]) !== -1){
                    count++;
                }
            }
            if(count == searchTextSplit.length){
                 returnArray.push(input[x]);   
            }
        }
        return returnArray;
    }
});

jsfiddle: http://jsfiddle.net/Cq3PF/

This filter makes sure that all search words are found.

Problem

I'm working through the AngularJS tutorial, and understand the basics of However, the out of the box implementation seems limited to just filter the list of items to the exact word or phrase entered in . Example: if the query is "table cloth", the result list can include a result with this phrase, "Decorative table cloth", but won't include "Decorative cloth for table" because the filter is just a continuous search string. I know there's the ability to add custom filters, but at first glance it seems like those are mainly transforms. Is there any way to add a custom filter so that both "Decorative cloth for table" and "Decorative table cloth" show up in the filtered result set?

Original source