Jed
Jed

Reputation: 1043

Ionic find contacts

I am trying to do a search in my Ionic 2 application on a phone number that has +1 in the front of it.

import { Component } from '@angular/core';


import { IonicPage, NavController, NavParams } from 'ionic-angular';
 import { CallNumber } from '@ionic-native/call-number';
 import {Contacts, Contact, ContactField, ContactAddress, ContactName,ContactFindOptions} from '@ionic-native/contacts';
 import {ContactInterface} from "../../models/interfaces/contactInterface";

 /**
 * Generated class for the ContactMenuPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-contact-menu',
  templateUrl: 'contact-menu.html',
})
export class ContactMenuPage {

  contact : ContactInterface;

  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              private callNumber: CallNumber,
              private contactCtrl: Contacts) {
      this.contact = this.navParams.get('contact');
      this.contact.exists = false;
  }

  ionViewDidLoad() {

    this.contact.exists = false;
    console.log(this.contact.cell[0]);

    var options = new ContactFindOptions();
    options.hasPhoneNumber = true;
    options.filter = this.contact.cell[0];
    options.multiple = true;

    this.contactCtrl.find(['phoneNumbers'], options).then(
        (contacts) => {
            console.log(contacts);
        }
    );



  }

Whenever i do this it just gives me the first contact that was added to the contacts list. It must not give me anything if there are no matches.

Could you give me some pointers?

Upvotes: 0

Views: 1344

Answers (1)

Jed
Jed

Reputation: 1043

The code above uses the contact plugin for cordova and it returns an array of contact objects. I dont know why it wasnt working before but now its working perfectly so the above code is fine

Upvotes: 2

Related Questions