Property removeContact does not exist on type 'Contacts'

Hi,

I’m using ionic 2

here’s my code:

import { Contacts, ContactFindOptions } from ‘@ionic-native/contacts’;
import { CallNumber } from ‘@ionic-native/call-number’;

@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’,
providers: [Contacts]
})

export class HomePage {
items: any[];
itemsAll: any[];

constructor(public navCtrl: NavController,private contacts: Contacts,private event: Events, private callNumber: CallNumber) {
this.initializeItems();
}

initializeItems() { this.items = [];
const options = new ContactFindOptions();
options.filter = ""
options.multiple = true;
options.hasPhoneNumber = true;

this.contacts.find([’*’], options)
.then(data => {
this.items = data;
this.itemsAll = data;
});

removeContact(item){
this.contacts.removeContact(); // error here
}

}
How can I handle this error?

Thanks

I did not find a removeContact() method for the Contacts object in the API on first glance. May be you are looking for the remove() method of the Contact object?

If the item object is a valid Contact object here, then try this:

removeContact(item){
   item.remove();
}

Additionally, you only very rarely want to be declaring providers on components, and I can’t think of a reason why this would be such a situation.

1 Like