drako9
drako9

Reputation: 1

issue with $cordovaContacts

I'm new in stackoverflow forum and I decide to create this topic to solve a problem which I'm stuck for 2 weeks.

I have the following:

I'm trying to use the ngCordova contacts module ( $cordovaContacts ) to retrieve the phone numbers of the contacts. The problem is that there is an error with the "navigator" object. I found that there is not possible to access the fields of these object ( functions, app, contacts, splashscreen ) so when I call to $cordovaContacts.find(...) it shows the error: "Can not find property find of undefined". I invested some time debugging and when I use:

console.log(navigator);

The console shows:

[object Object]

services.js (21,15)

CordovaNavigator

_ {_

_ [functions]: ,_

_ proto: { },_

_ app: { },_

_ contacts: { },_

_ splashscreen: { }_

_ }_

But when I print navigator.contacts object it shows undefined

I also tried to use navigator.CordovaNavigator but is also undefined.

This code is called when loading controllers.

I have no idea why it shows that navigator has an attribute contacts and then when I call it it shows UNDEFINED . Maybe I need to stablish some access rights?

I'm really lost so anything you tell me will help. Thanks a lot.

Upvotes: 0

Views: 58

Answers (1)

Borut
Borut

Reputation: 13

If you are trying to fetch the contacts on controller load (means, that you don't trigger it manually inside another method or via a timeout / interval), you'll need to wrap it with the ionicPlatform.ready() method, else the plugin isn't ready at that point.

ionic.Platform.ready(function(){
    $cordovaContacts.find().then(function(allContacts) {
        $scope.contacts = allContacts;
    });
});

Upvotes: 0

Related Questions