Skip to content

Commit

Permalink
First contact load fix, group load and order fix #312
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored and skjnldsv committed Mar 31, 2016
1 parent 3da03eb commit 130ae25
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions js/components/contactList/contactList_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,22 @@ angular.module('contactsApp')
});
});

// Get contacts
ContactService.getAll().then(function(contacts) {
$scope.$apply(function() {
ctrl.contacts = contacts;
if (!_.isEmpty(ctrl.contacts)) {
ctrl.setSelectedId(_.sortBy(contacts, function(contact) {
return contact.fullName();
})[0].uid());
}
ctrl.loading = false;
});
});

// Wait for ctrl.contactList to be updated, load the first contact and kill the watch
var unbindListWatch = $scope.$watch('ctrl.contactList', function() {
if(ctrl.contactList && ctrl.contactList.length > 0) {
ctrl.setSelectedId(ctrl.contactList[0].uid());
ctrl.loading = false;
unbindListWatch();
}
});

$scope.$watch('ctrl.routeParams.uid', function(newValue) {
if(newValue === undefined) {
// we might have to wait until ng-repeat filled the contactList
Expand Down

0 comments on commit 130ae25

Please sign in to comment.