336190 (2) [Avatar] Offline
your book is awesome, but during my Ionic development I got following problem:

I want to show contact list from my device and it works fine for 0 - 300 contacts. But I tested it on device with 800 contacts and it takes about 12 seconds. During this 12 seconds I can't do anything except of showing $ionicLoading icon, because request to cordova doesn't work asynchronously and I have to wait. I'd like to load contact list in background without 10s freezing. Is it possible somehow?
Btw it's not problem with rendering contacts in template, but in cordova find function.

var options = {};
options.filter = "";
options.multiple = true;
options.fields = ['name.formatted', 'photos', 'emails'];

$cordovaContacts.find(options).then(function (result) {
}, function (error) {
    console.log("ERROR: " + error);

Thank you
jeremy.wilken (208) [Avatar] Offline
From the plugin documentation the find method is async. https://github.com/apache/cordova-plugin-contacts/blob/master/doc/index.md

The navigator.contacts.find method executes asynchronously, querying the device contacts database and returning an array of Contact objects. The resulting objects are passed to the contactSuccess callback function specified by the contactSuccess parameter.

That does make a difference in how you handle this situation. You might have to block the interface with $ionicLoading since the call is async. I'm not sure what your situation is, or what the user experience you have in mind should be.

I did a little research and this is a known issue with the Cordova plugin. Here is one issue where they did improve the speed some https://issues.apache.org/jira/browse/CB-1250. It seems that 12 seconds for 800 contacts may be fairly common and expected.

You might consider using the pickContact plugin feature, since that would likely be faster than loading the full list yourself.
336190 (2) [Avatar] Offline
It should be async, but it doesn't work like that.
I created new Ionic project only for loading contacts without other fuctionalities. There is no ionicLoading, but problem is the same. After click on the button and contacts are loading, I can't do anything else.

There is my project, if you want to see that:
Ionic project: https://dl.dropboxusercontent.com/u/25736835/zralbych.zip
iOS app for load demo contacts to device or simulator: https://github.com/Janak-Nirmal/DummyContacts
jeremy.wilken (208) [Avatar] Offline
I rebuilt the project and moved your app code into it, and in my simulator for iOS with 806 contacts it was taking about 1-2 seconds. Have you tried on other devices? It would be slower on older devices, but I don't have any on hand to try right now.

I did see the lag, where it seemed to freeze execution of other things until the contacts resolve. I couldn't change tabs for example until the list resolved. In a cursory glance through the source code, ngCordova uses a promise and the Contacts plugin claims to work asynchronously, so I'm not entirely sure why this might be happening. I would suggest reaching out to the Cordova plugin community to get more insight into this. I did try it without ngCordova, so it seems to be the Contacts plugin and not the ngCordova wrapper.