Anand Anand - 2 months ago 10
TypeScript Question

Error : connot find name 'ContactField' in ionic 2

I have to save the contact using Ionic2 but when I run the app using cmd I'm getting an error. I have installed

cordova-plugin-contacts


Here is my code

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Contacts} from 'ionic-native';
@Component({
templateUrl: 'build/pages/contact/user-add/user-add.html',
})
export class UserAddPage {
name:any;
number:any
constructor(private navCtrl: NavController) {
}
addcontact(){
var contact=Contacts.create();
contact.displayName=this.name;
contact.nickname=this.name;

var contactfield=new ContactField();
contactfield.type="mobile";
contactfield.value=this.number;
contactfield.pref=true;

var numbersection=[];
numbersection.push(contactfield);
contact.phoneNumbers=numbersection;

contact.save().then((data)=>{
console.log('saved',data);
},(error)=>{
console.log('error',error);
})
}
}


After that I'm getting this error

enter image description here

Answer

You just need to import it like this:

import { Contact, ContactField } from 'ionic-native';
Comments