Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Contacts plugin issue: Cannot set property 'name' of undefined #166

Closed
candradeg9182 opened this issue Aug 29, 2018 · 0 comments
Closed

Comments

@candradeg9182
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant