Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70440

Ionic Native Contact promise not working

$
0
0

@Naveen512 wrote:

import { Component, OnInit} from '@angular/core';
import {Contacts,Contact,IContactFindOptions,ContactFieldType,} from '@ionic-native/contacts/ngx';

@Component({
  selector: 'app-tab1',
  templateUrl: 'tab1.page.html',
  styleUrls: ['tab1.page.scss']
})
export class Tab1Page implements OnInit {
  
  contact:Contact
  field:ContactFieldType[] = ["displayName", "phoneNumbers"];
  constructor(private contacts:Contacts
              ){
  }
  test:any = [];
  ngOnInit(){
    
  }
  getContacts(){
     let options:IContactFindOptions = {
       filter:'r',

     }
    this.contacts.find(this.field,options)
    .then((contacts) => {
      console.log(contacts);
      for(let i=0;i<contacts.length;i++){
        let contact = {
          name:'',
          phone:''
        }
        contact.name = contacts[i].displayName;
        contact.phone = contacts[i].phoneNumbers[0].value;
        this.test.push(contact);
      }
      
    });

  }
}

``
Error:
Tab1Page.html:13 ERROR TypeError: Cannot read property 'then' of undefined
    at Tab1Page.push../src/app/tab1/tab1.page.ts.Tab1Page.getContacts (tab1.page.ts:25)
    at Object.eval [as handleEvent] (Tab1Page.html:13)
    at handleEvent (core.js:23107)
    at callWithDebugContext (core.js:24177)
    at Object.debugHandleEvent [as handleEvent] (core.js:23904)
    at dispatchEvent (core.js:20556)
    at core.js:21003
    at HTMLElement.<anonymous> (platform-browser.js:993)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Object.onInvokeTask (core.js:17290)

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70440

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>