Ng-repeat index in alphabetical format
2 answers
Here is the solution I found:
JavaScript:
// the alphabet
$scope.alphabet['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
// get the index and return the letter of the alphabet
$scope.getLetter = function(index) {
return $scope.alphabet[index];
};
HTML:
<div ng-repeat="name in names">{{getLetter($index)}}</div>
Edit (thanks to @TheShalit and @patrick):
JavaScript:
// get the index and return the letter of the alphabet
$scope.getLetter = function(index) {
return String.fromCharCode(65+index);
};
HTML:
<div ng-repeat="name in names">{{getLetter($index)}}</div>
+5
source to share