I'm trying to build a list of people with dividers for each letter (similar to a phone's address book).
people = ['Angela','Annie','Bob','Chris']; Result: A Angela Annie B Bob C Chris I want to do something similar to this pseudocode using Angular:
<div id="container" ng-init="lastCharacter = ''"> @foreach(person in people) @if(firstCharacter(person.name) != lastCharacter) <div class="divider-item">{{firstCharacter(person.name)}}</div> {{lastCharacter = firstCharacter(person.name)}} @endif <div class="person-item">{{person.name}}</div> @endforeach </div> What is the easiest way to achieve this? I couldn't come up with an elegant solution using ng-repeat.