While attempting to use Ionic2 to save a contact, an error occurs when running the app through the command line. The cordova-plugin-contacts
has been properly installed.
Below is the code snippet:
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);
})
}
}
Upon execution, the following error is encountered: