Bring in smartphone contacts

Asked

Viewed 65 times

1

I made an application to bring the contacts from the device. My doubt is the following when I bring the phone it brings me an array, with type:mobile, value="" with the phone, how can I do a treatment to bring only the number?

Segue um print de como está vindo meus contatostexto em negrito

        <ion-list>
            <ion-item ng-repeat="contact in contacts">
                {{contact.displayName}}, {{contact.phoneNumbers}
            </ion-item>
        </ion-list>


    .controller("contatosCtrl", function ($scope, $cordovaContacts) {

        $scope.getContactList = function () {
            $cordovaContacts.find({
                filter: ''
            }).then(function (result) {
                $scope.contacts = result;
            }, function (error) {
                console.log("ERROR: " + error);
            });
        }

    });
  • Since it is an array, you will have to use ng-repeat to pick up each phone, or use {{contact.phonenumbers[0]. value}} to pick up the first one. But this may give error if there is no element in the array.

  • All right, I’ll try it here, @Rafael.

  • @Rafael ,I was able to solve, using the way you indicated and so I also found another error of mine, I had put a key to more "{{contact.phonenumbers[0]. value}}". Thank you very much!

1 answer

1


The solution to the problem was using the position of the array, goes down as it went down.

{{contact.displayName}}, {{contact.phoneNumbers[0].value}}

  • 1

    Mark your answer as correct then.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.