I have a list of states (Florida, Alabama ...) and I want to create named anchors above the first occurance of the first letter.
Letter Links
<nav>
<ul class="letters">
<li ng-repeat="letter in locations.getLetters()">
<a href="#{{letter}}">{{letter}}</a>
</li>
</ul>
</nav>
States
<nav>
<ul class="locations">
<li ng-repeat="state in locations.states">{{state.state}}
<a ng-if="" id="{{state.state.charAt(0)}}">fgsdf</a>
<ul>
<li ng-repeat="city in state.cities">
<a href>{{city.name}}</a>
</li>
</ul>
</li>
</ul>
</nav>
I am stuck at <a ng-if="" id="{{state.state.charAt(0)}}">fgsdf</a>
I have tried ng-if="!document.getElementById(state.state.charAt(0))"
and that doesn't work. Does anyone have any suggestions as to how I should go about this?
Update
I've considered using angular's built-in filters to filter the states in ngRepeat
. When a user clicks A
, only the states starting with A should show. This seems like a much cleaner and more intuitive approach and will improve UX.