Cordova Contacts plugin with Searchbar

i have used the cordova Contacts plugin to get the contact list in the application.
i have put the search bar on top to search within the list.

Typescript**
Method to initialize the pluging
getContactList(){

let options = {
  multiple: true,
  hasPhoneNumber: true,
  contactFields: ['displayName']
}
Contacts.find(['*'], options).then((contact) => {
  this.contactarray = contact;      
  console.log(this.contactarray); // This shows the complete object.      
  console.log(this.contactarray.displayName); // it says undefined :( IDK why....
}, (err) => {})

}

HTML*

{{contact.displayName}}

Here i got the displayName property of the contact object and is displays the contact names perfectly, but i am not able to get displayName property in TS file.

Requirement**
i need the displayName property in the TS file to let the searchbar works properly…

Thanks

3 Likes

The below code working for me. Searches for all contacts those have ‘ra’ in their displayName

findContact(){
let options = {
multiple: true,
hasPhoneNumber: true,
filter: ‘Ra’
}
let cantactFields = [‘displayName’];
Contacts.find(cantactFields, options).then(res => {
for(var i=0; i<res.length; i++){
alert(res[i].displayName);
}
}, (er) => {

  })

}