Created
January 5, 2017 14:53
-
-
Save bora89/2bea2d3f428df41e5353c4100603cafd to your computer and use it in GitHub Desktop.
Simple custom angular repeat filter
From https://toddmotto.com/everything-about-custom-filters-in-angular-js/
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
| app.filter('startsWithA', function () { | |
| // function to invoke by Angular each time | |
| // Angular passes in the `items` which is our Array | |
| return function (items) { | |
| // Create a new Array | |
| var filtered = []; | |
| // loop through existing Array | |
| for (var i = 0; i < items.length; i++) { | |
| var item = items[i]; | |
| // check if the individual Array element begins with `a` or not | |
| if (/a/i.test(item.name.substring(0, 1))) { | |
| // push it into the Array if it does! | |
| filtered.push(item); | |
| } | |
| } | |
| // boom, return the Array after iteration's complete | |
| return filtered; | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment