I'm attempting to sort through a group of individuals based on the first letter of their first name within an AngularJS repeater.
Here's how the repeater looks:
<li ng-repeat="person in people | orderBy: 'firstname' | firstLetter:'firstname':'A'">
<a ui-sref="people.details({ personId: {{person.id}} })">
<span class="list__icon"><img src="img/avatar.png"></span>
<span class="list__text">
<span class="list__text__name">{{person.firstname}} <b>{{person.lastname}}</b></span>
</span>
</a>
</li>
First, I organize it by first name and then apply a personalized filter called firstLetter
:
.filter('firstLetter', function () {
return function (input, letter) {
input = input || [];
var out = [];
input.forEach(function (item) {
if (item.charAt(0).toLowerCase() == letter) {
out.push(item);
}
});
return out;
}
});
Nevertheless, I encounter an error stating that charAt
is not a function... Could I be passing the arguments to the filter incorrectly?