Search code examples
androidangularjscordovaionic-frameworkngcordova

Get all contacts at least one phone number in ngCordova Contacts plugin


I am using the ngcordova contacts plugin to retrieve the contacts in an app. I'd like to know if it is possible to get only the contacts that have at least one phone Number.

I have use the following code , It returns the my google contacts which contains email but not phone numbers. But I want only available phone number not emails. Is this possible ? or any other option available to get this result.

$scope.getContactList = function() {
         $ionicLoading.show({
            template: 'Loading...'
        });
        var options = {};
        options.multiple = true;
        options.hasPhoneNumber = true;
        options.fields = ['name.formatted', 'phoneNumbers'];
        $cordovaContacts.find(options).then(function(result) {
            $scope.contacts = result;
            $ionicLoading.hide();

        }, function(error) {
            console.log("ERROR: " + error);
        });
    }

Solution

  • I got solution without using any external js , code shown as follows :

    $scope.getContactList = function() {
          $scope.contacts = [];
                 $ionicLoading.show({
                    template: 'Loading...'
                });
                var options = {};
                options.multiple = true;
                $cordovaContacts.find(options).then(function(result) {
                     for (var i = 0; i < result.length; i++) {
                        var contact = result[i];
                         if(contact.phoneNumbers != null)
                           $scope.contacts.push(contact);
                      }
                    $ionicLoading.hide();
                }, function(error) {
                    console.log("ERROR: " + error);
                });
        }