I have an array of strings which I'd like to filter by first letter using a custom angular filter.
I have the following ng-repeat
set up:
<div ng-repeat="proverb in proverbs | firstLetter">
<a href="#/{{langID}}/{{$index}}">{{proverb}}</a>
</div>
And this is my custom filter, currently using a default letter "A"
for testing purposes:
angular
.module('raidersApp', [
'ngRoute',
'ngTouch',
'ngResource'
])
.filter('firstLetter', function () {
return function (input) {
input = input || [];
letter = "A";
var out = [];
input.forEach(function (item) {
console.log("current item is", item, item.charAt(0));
if (item.charAt(0).toUpperCase() == letter) {
out.push(item);
}
});
return out;
};
})
The problem is, this filter is currently filtering everything out (the app works and there are no console errors but the ng-repeat
section is blank), and the console.log
is never even being displayed.
What's missing?
Copyright Notice:Content Author:「Tiago」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30264315/custom-angular-filter-never-called