Created
June 20, 2013 18:37
-
-
Save i8ramin/5825377 to your computer and use it in GitHub Desktop.
Angular JS filter that behaves much like the built in filter one, but allows you to filter with multiple values, space separated. For example "big orange round"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
angular.module('ConferenceRoomApp').filter('multifilter', function ($filter) { | |
return function (collection, query) { | |
var filteredCollection = collection; | |
var queryTokens = query ? query.split(' ') : [query]; | |
// user entered more than word | |
if (queryTokens.length > 1) { | |
for (var i = 0; i < queryTokens.length; i++) { | |
filteredCollection = $filter('filter')(filteredCollection, queryTokens[i]); | |
} | |
} else { | |
filteredCollection = $filter('filter')(collection, queryTokens[0]); | |
} | |
return filteredCollection; | |
}; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment