I have an array of objects and need to separate it by the letters of the alphabet, so I need to limit the items by the corresponding letter.
Example:
A - Aston Martin
B - Bugatti
angular.module("myApp", [])
.controller("myCtrl", function ($scope) {
$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"
];
$scope.brands = [
{"brand": "Ferrari"},
{"brand": "Aston Martin"},
{"brand": "Koenigsegg"},
{"brand": "Lamborghini"},
{"brand": "Bugatti"},
{"brand": "Maserati"},
{"brand": "Pagani"},
{"brand": "Porsche"}
]
});
.multi-column {
column-count: 3;
column-gap: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><bodyng-app="myApp">
<div class="container" ng-controller="myCtrl">
<div class="row">
<div id="{{letter}}" class="col-xs-12" ng-repeat="letter in alphabet">
<h2>{{letter}}</h2>
<ul class="list-unstyled multi-column">
<li ng-repeat="x in brands"><a href="">{{x.brand}}</a></li>
</ul>
</div>
</div>
</div>
</body>
Also add codepen.io
And so on.