Ramzy Abourafeh
Ramzy Abourafeh

Reputation: 1195

Getting the phoneNumber using $cordovaContacts

I'm trying to get all the contacts in the phone using ng-cordova, I success to do that like the following, I create a service in AngularJS:

    .factory("ContactManager", function($cordovaContacts) {
    return {
        getContacts: function() {
            var options = {};
            options.filter = "";
            options.multiple = true;

            //get the phone contacts
            return $cordovaContacts.find(options);
        }
    }
})

Also the method find in the ng-cordova is't like the following:

 find: function (options) {
    var q = $q.defer();
    var fields = options.fields || ['id', 'displayName'];
    delete options.fields;

    navigator.contacts.find(fields, function (results) {
        q.resolve(results);
      },
      function (err) {
        q.reject(err);
      },
      options);

    return q.promise;
  }

And did the following inside the controller:

        ContactManager.getContacts().then(function(result){
            $scope.users= result;

        }, function(error){
            console.log(error);
        });

I noticed that in the $scope.users I find the formatted, middleName ..., but I can't find the phoneNumber, how can I get also the phoneNumbers?

Upvotes: 2

Views: 399

Answers (1)

Dylan
Dylan

Reputation: 4773

If you log the contacts you should see an object with a phoneNumbers array in it.

   ContactManager.getContacts().then(function(result){
        $scope.users= result;
        console.log(result);
    ...

If you don't it's something else.

I also made a somewhat close mock json of what the return looks like.

Upvotes: 1

Related Questions