I am trying to query the all contacts using ionic 2 native. I got the following error while run the ionic serve command. How can i over come this issue if anyone know let me know please. Thank you
Typescript Error
Property 'find' does not exist on type 'typeof Contacts'.
home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Contacts, Contact, ContactField, ContactName } from '@ionic-native/contacts';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController) {
}
testFun(){
Contacts.find(['*']).then((contacts)=>{
alert(JSON.stringify(contacts[0]));
})
}
}
home.html
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<button ion-button full (click)="testFun()">Get Contacts</button>
</ion-content>
source codeGit repo for my project
Since Ionic 3.x.x, the way you use Native plugin is a little different from Ionic 2.x.x
Contact
in your constructorContact
in your @ComponentSo your home.ts should looks like this instead:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Contacts, Contact, ContactField, ContactName } from '@ionic-native/contacts';
@Component({
selector: 'page-home',
templateUrl: 'home.html',
providers: [Contacts]
})
export class HomePage {
constructor(public navCtrl: NavController, private contacts: Contacts) {
}
testFun(){
this.contacts.find(['*']).then((contacts)=>{
alert(JSON.stringify(contacts[0]));
})
}
}
More usage example check the official doc for Ionic 3.x NATIVE doc here http://ionicframework.com/docs/native/contacts/