This code below is in my provider directory and is supposed to return an array of contacts
import { Injectable } from '@angular/core';
import { NavController } from 'ionic-angular';
import {Contacts, Contact, ContactField, ContactAddress, ContactName, ContactFindOptions} from '@ionic-native/contacts';
getAllContacts() {
return this.contacts.find(
["displayName", "phoneNumbers"],
{multiple: true, hasPhoneNumber: true}
)
.then((contacts) => {
for (var i=0 ; i < contacts.length; i++){
if(contacts[i].displayName !== null) {
var contact = {};
contact["name"] = contacts[i].displayName;
contact["number"] = contacts[i].phoneNumbers[0].value;
this.contactList.push(contact);
}
}
return this.contactList;
});
}