Ionic 2 native pin contact plugin doesn't come out

I am trying to request all contacts using native2. When running the ion command command, I received the following error. How can I get through this problem if anyone knows let me know please. Thanks 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>

Error image enter image description here

Git repo source code for my project

+4
source share
2 answers

Since Ionic 3.xx, the way you use the Native plugin is slightly different from Ionic 2.xx

  • First you need to add Contactto your constructor
  • You need to add providers Contactto @Component

, 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',
  providers: [Contacts]
})
export class HomePage {

  constructor(public navCtrl: NavController, private contacts: Contacts) {

  }

  testFun(){
    this.contacts.find(['*']).then((contacts)=>{
      alert(JSON.stringify(contacts[0]));
    })
  }
}

Ionic 3.x NATIVE doc http://ionicframework.com/docs/native/contacts/

+3

?

Contacts.prototype.find(['*'])
            .then((contacts)=>{
                alert(JSON.stringify(contacts[0]));
            })
            .catch((err) => {
                alert('Error ' + err);
});
-1

Source: https://habr.com/ru/post/1675549/


All Articles