ngCordova contacts doesn't work

Hello, I’m new with ngCordova and ionic.

I tried to list contact from my device, but when I use $cordovaContacts.find(), it doesn’t work.

Here my code

app.controller('HomeCtrl', function($scope, $cordovaContacts, $ionicPlatform) {
  console.log($cordovaContacts);

  var opts    = {
    filter      : '',
   multiple    : true,
   fields      : ['displayName']
  };

 $cordovaContacts.find(opts).then(function(contacts) {
   console.log(contacts);
 });
});

And I have error

TypeError: Cannot read property 'find' of undefined

Did I do something wrong ?

I already installed ngCordova and ngCordova contact.

Thanks you

Have you included ng-cordova.min.js file before cordova.js file?

Have you injected ngCordova module?

angular.module('starter', ['ionic', 'ngCordova'])

yes I already did that. I haven’t no error about inclusion etc. When I try to console.log($cordovaContacts); all methods are there, but I can’t use them

Anyone please ?
It seems ngCordova contacts doesn’t work at all

I have this same issue but on selected devices/platforms in the xdk emulator.Works on some android devices, fails on the ios devices I could test on.Would appreciate assistance

I found the solution for your problem. Read the forum post below, it also has a working example.

But in few words, plugin documentation forgot to mention you need to use Cordova or Ionic ready state before you can use this plugin.

I just only need the plugin to find all contacts on ios devices, so I can’t comment on other platforms, but the documentation suggests find() will find all contacts. I can only make it find all by passing an options hash i.e. find({filter: ‘’,multiple:true}).

Hope this helps.

2 Likes

Definitely right. Same in Android. Find() with no parameters throws an error.

hello,This solution was easy for me to understand as a beginner but I still could not access contacts on ios. getting the same error “TypeError: Cannot read property ‘find’ of undefined”.Can you please help me?

Hello,

I face it on my local ionic serve environment as the contacts plugin is available only on the device itself…

Therefore I have developed a simple mock contacts service for dev environment which uses the local storage instead:

Cheers,
Meir.