Created
June 3, 2018 00:13
-
-
Save ezetojo/5c815aa4f108bce1107c51215371e1ea to your computer and use it in GitHub Desktop.
AngularJS Agenda (Contact List Alphabetically Ordered and Separated by First Letter)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular | |
.module("app", []) | |
.controller("appCtrl", function ($scope) { | |
$scope.contacts = [{"name": "John"},{"name": "Ben"},{"name": "Hal"},{"name": "Mimi"},{"name": "Simone"},{"name": "Harry"},{"name": "Brooke"},{"name": "Kirsten"},{"name": "Maureen"},{"name": "Annabel"},{"name": "Rian"},{"name": "Melody"},{"name": "Lucy"},{"name": "Ross"}]; | |
$scope.alpabeth = []; | |
angular.forEach($scope.contacts, function (cv, ck) { | |
if ($scope.alpabeth.indexOf(cv.name.charAt(0)) == -1) { | |
$scope.alpabeth.push(cv.name.charAt(0)); | |
}; | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-app="app"> | |
<div ng-controller="appCtrl"> | |
<div ng-repeat="l in alpabeth | orderBy:l track by $index"> | |
<ul> | |
<h4>{{l}}</h4> | |
<li ng-repeat="c in contacts | orderBy:c.name track by $index" ng-if="c.name.charAt(0) == l"> | |
{{c.name}} | |
</li> | |
</ul> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment