ngCordova contacts doesn't work


#1

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


#2

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

Have you injected ngCordova module?

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

#3

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


#4

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


#5

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


#6

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.


#7

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.


#8

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


#9

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?


#10

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.