Contacts plugin issue: Cannot set property 'name' of undefined
Closed this issue · 0 comments
Hi,
When I try to assign this :
new ContactName(null, 'Smith', 'John');
into contact.name :
let contact: Contact = this.contacts.create();
let usuario = new ContactName(null, 'Smith', 'John');
console.log(typeof usuario)
contact.name = new ContactName(null, 'Smith', 'John'); <-- failure occurs here
contact.phoneNumbers = [new ContactField("mobile","6471234567")];
contact.save().then(
() => console.log("Contact saved!", contact),
(error: any) => console.error("Error saving contact.", error)
);
}
I get an error:
ERROR TypeError: Cannot set property 'name' of undefined
at Contact.set [as name] (decorators.js:195)
at HomePage.add (home.ts:85)
at Object.eval [as handleEvent] (HomePage.html:191)
at handleEvent (core.js:13589)
at callWithDebugContext (core.js:15098)
at Object.debugHandleEvent [as handleEvent] (core.js:14685)
at dispatchEvent (core.js:10004)
at core.js:10629
at HTMLButtonElement. (platform-browser.js:2628)
at t.invokeTask (polyfills.js:3)
I im indeed importing :
import { Contacts, Contact, ContactField, ContactName } from '@ionic-native/contacts';
Into the page that I want to use it, and I'm importing the contacts into the constructor.
Also I'm adding into providers the
import { Contacts} from '@ionic-native/contacts';
and I have installed :
$ ionic cordova plugin add cordova-plugin-contacts
$ npm install --save @ionic-native/contacts