Hello,
How can I get my contacts list?
I tried this:
findContacts() {
this.options = new ContactFindOptions();
this.options.filter = "";
this.options.multiple = true;
this.fields = ["displayName"];
this.nav.contacts.find(this.fields, this.contactfindSuccess, this.contactfindError, this.options);
}
contactfindSuccess(contacts) {
for (this.i = 0; this.i < contacts.length; this.i+=1) {
alert("Display Name = " + contacts[this.i].displayName);
}
}
contactfindError(message) {
alert('Failed because: ' + message);
}
I got this errors:
Error TS2305: Module ââ/home/ubuntu/workspace/WriteNow/node_modules/ionic-angular/indexââ has no exported member âContactFindOptionsâ.
Error TS2339: Property âcontactsâ does not exist on type âNavControllerâ.
Thank you,
sagi
hi, have you solved this problem⌠I am also stuck on this, cannot list contacts
abuder
April 20, 2017, 2:22pm
3
That works fine
import { Component } from '@angular/core';
import { NavController, MenuController, AlertController} from 'ionic-angular';
import { Contacts, ContactFieldType, ContactFindOptions } from 'ionic-native';
import { Http, Headers, RequestOptions } from '@angular/http';
import { Storage } from '@ionic/storage';
import * as globalvars from '../../../app/globalvars';
@Component({
selector: 'page-importData',
templateUrl: 'importData.html'
})
export class ImportDataPage {
public allContacts: any
/**
* @param {NavController} public navCtrl
* @param {MenuController} public menuCtrl
*/
constructor(public navCtrl: NavController, public menuCtrl : MenuController, public storage: Storage, public http: Http, public alertCtrl: AlertController) {
Contacts.find(['displayName', 'name', 'phoneNumbers', 'emails'], {filter: "", multiple: true})
.then(data => {
this.allContacts = data
});
}
}
7 Likes
Hi, I tried this code on my first application and while Iâm fetching the contacts to a list, it just shows [object object]. Doesnât show any contact name or phone number.
home.ts
getContacts(){
this.contacts.find([âdisplayNameâ, ânameâ, âphoneNumbersâ], {filter: ââ, multiple: true})
.then(data => {
this.allContacts = data
});
html
<button ion-button (click) =âgetContacts()â>Add Contacts
<ion-item *ngFor=âlet contact of allContactsâ>
{{ contact }}
1 Like
may be you have to use json.parse
orjson.stringnify
method to get contacts data
Tried it but doesnât work. Still shows [Object] instead of actual output.
jaydz
April 2, 2018, 11:32pm
8
Thatâs because a Contact is an object. You would need to specify what you want to display.
{{ contact.displayName }}
Or
{{ contact.name.givenName }}
Etc