Last active
August 29, 2015 14:07
-
-
Save BenjaminKobjolke/ab903d3a44c2fe9ea724 to your computer and use it in GitHub Desktop.
Filter
This file contains hidden or 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
<input type="text" ng-model="letter"> | |
<ul> | |
<li ng-repeat="friend in person.friends | startsWithLetter:letter"> | |
{{ friend }} | |
</li> | |
</ul> |
This file contains hidden or 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
http://toddmotto.com/everything-about-custom-filters-in-angular-js/ | |
app.filter('startsWithLetter', function () { | |
return function (items, letter) { | |
var filtered = []; | |
var letterMatch = new RegExp(letter, 'i'); | |
for (var i = 0; i < items.length; i++) { | |
var item = items[i]; | |
if (letterMatch.test(item.name.substring(0, 1))) { | |
filtered.push(item); | |
} | |
} | |
return filtered; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment