Getting contacts displayName and phoneNumbers


#1

Hi guys…I am using ionic contacts native for getting the list of contact from phone

.ts:

import { Contacts } from 'ionic-native';
 /////////
 export class ContactPage {
   contactsfound = []

  constructor(public navCtrl: NavController) {
    Contacts.find(["displayName", "phoneNumbers"], {multiple: true}).then((contacts) => {
      this.contactsfound = contacts;
     })
    }
   }

.html:

   <ion-content>
     <ion-list>
        <ion-list-header>Follow us on Twitter</ion-list-header>
           <ion-item *ngFor="let item of contactsfound">
            {{ item.displayName }}
           <p>{{ item.phoneNumbers }}</p> 
          </ion-item>
        </ion-list>
     </ion-content>

I am getting the list of displayName correctly however for phoneNumbers i get [object Object]
How to do this??
Also, I want to have a letter on the left-side of the list where is represents the first letter of a group of contacts starting with that letter (e.g. A list group then scrolling B list group) … it would be great if someone provides an insight regarding this. thanx


#2

Guys , i need help… I am still unable to show the phoneNumbers!


#3

Hello You r so lucky because i am far away what u did i couldnt any of them this is my code

import { Contact, Contacts, ContactField } from ‘ionic-native’;

///////////////////////////
contac:any[];

constructor(public navCtrl: NavController,public alertCtrl:AlertController, public loadingCtrl:LoadingController) {
this.contac=[]
}

getcontacts(){
let loader = this.loadingCtrl.create({
content: “Doing important work…”,
});
loader.present();

Contacts.find(["displayName"]).then((con)=>{this.contac=con;console.log("promise içindeki con listesi",con)},(err)=>{}).then(()=>{loader.dismiss();})
loader.onDidDismiss(()=>{console.log("Burası Loader okunmasının bitimi concat",this.contac)})

}

}

i put loader because not to miss any contacts

Could you help me to get at least display name Thank you in Advance


#4

what you are doing is correct… besides I don’t see your html side… also it presents error if you are running with ionic serve , you should run on phone ionic run android --prod --device

follow this to learn how to debug using dev tools with your phone connected (to retrieve contact data) and then you can log and see how the retrieved array looks like and how to access it properly

I also posted a question , and provided answer too but in a little different way… I took what I needed from contacts (name and number) and stored in new array (for saving them in storage so not everytime it keeps loading, and just get it from storage when the user navigates again to contacts) but you have to also take care of when there is a number added/removed from the contacts , and how your app should update that piece of info (or keep loading everytime, its up to you)


#5

Gorgeous anwser Thanks alot i ll try ur advice asap


#6

Hello there i m so sory to distubing you but Maybe u can help me on an other issu .I m using Nadroid studio to run app on android but android studio makes my comp so slow and it takes time .However when i use CLİ with ionc run android it gives this error

BUILD SUCCESSFUL

Total time: 55.886 secs

Built the following apk(s):
C:/Users/home/TopluMesaj/platforms/android/build/outputs/apk/android-debug.apk

ANDROID_HOME=C:\Users\home\Documents

JAVA_HOME=C:\Program Files\java\jdk1.8.0_121

Error: cmd: Command failed with exit code 1 Error output:
‘adb’ is not recognized as an internal or external command,
operable program or batch file.

How can i fix this problem can u suggest any link to find a proper solution.

Thank you again i hope i dont make you busy so much


#7

Im not really sure… but it seems your device is not discovered…its trying to run it on an emulator instead. its better if you post a question


#8

did you get a solution to the [object, object] issue? I am having that problem too :frowning:


#9

@skmasinda A Contact’s phoneNumbers is an array of phone numbers, even if they only have 1.

So you need a secondary list to display each one


#10

u can lot of help here:-

hope this helps u too.