'How to select contact using contact.pickContact in ionic 5

I want to display selected contact using ionic native contact.pickContact. But the issue is this code doesn't work in case of one contact having multiple numbers. This only work with single number.

pickContact(){
   this.contacts.pickContact().then((contact)=>{
      console.log("Selected contacts: "+ JSON.stringify(contact));
      this.contactName = contact.displayName; 
      this.contactNumber = contact.phoneNumbers[0].value; 
   });
}


Solution 1:[1]

The cordova contact plugin return phoneNumbers which is an array of all the contact's phone numbers. so you can do it using a function like that:

getContactPhoneNumbersList(phoneNumbers) {
   let mobileString = '';
   phoneNumbers.forEach((number) => {
       if (mobileString) mobileString += ' | ';
       mobileString += number.value;
   });
}

pickContact(){
  this.contacts.pickContact().then((contact)=>{
  console.log("Selected contacts: "+ JSON.stringify(contact));
  this.contactName = contact.displayName; 
  this.contactNumber = getContactPhoneNumbersList(contact.phoneNumbers); 
});
}

for more information you can see cordova-plugin-contacts official website.

Solution 2:[2]

getContact(parameter:string){
    this.contact.pickContact().then((data) => {
var pNumber = data.phoneNumbers[0].value;
    });
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Louay Sleman
Solution 2 Jasper