$cordovaContacts not working

Hi, tried to follow the instrcuction on how to get the phone contacts, but if get “Cannot read property ‘find’ of undefined” … the $cordovaContacts object is empty… can anyone help? thanks

Did you add the cordova plugin to your project:

cordova plugin add cordova-plugin-contacts

Yes. I added the plug in and added ngCordova to index.html

HI,you must add $cordovaContacts.find() in the $ionicPlatform.ready(function() { }),do you try ?

1 Like

a459295360 is correct, make sure you wrap your find method in the $ionicPlatform.ready function.

Also, cordovaContacts find method takes in an options object, so make sure you are including that.

My code looks like this :

  var opts = {
    multiple: true,
    fields:  [ 'displayName', 'name' ]

  if (ionic.Platform.isAndroid()) {
    opts.hasPhoneNumber = true;

            // Do yo thang with all the contacts!

I have this in its own controller for my contact search view, and its working great on iOS and Android. On Android, even with 1000+ contacts, it still only takes a second or two. I just display a spinner while it retrieves the contacts.

1 Like

This saved my day long agony. Thanks !!!

im facing same issue cant find any wayout.