Ionic 4 beta Contact create not working

hello ,

i have worked on ionic 4 beta and angular cli 6.1.4
when i have install contact plugin and put the doc code in my application then show error.

core.js:1633 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'then' of undefined
TypeError: Cannot read property 'then' of undefined

here is my code
app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, RouteReuseStrategy, Routes } from '@angular/router';
import { HttpModule } from '@angular/http';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { Contacts } from '@ionic-native/contacts/ngx';


import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';


@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),  
    AppRoutingModule,
    HttpModule
  ],
  providers: [
    StatusBar,
    SplashScreen,
    Contacts,  
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

My page code

import { Contacts, Contact, ContactField, ContactName } from '@ionic-native/contacts';

@Component({
  selector: 'app-addvisitor',
  templateUrl: './addvisitor.page.html',
  styleUrls: ['./addvisitor.page.scss'],
  providers: [Contacts]
})

constructor(private contacts: Contacts) {  
    this.addContact();
  }

addContact() {

    let contact: Contact = this.contacts.create();

    contact.name = new ContactName(null, 'Smith', 'John');
    console.log(contact.name);
    contact.phoneNumbers = [new ContactField('mobile', '6471234567')];
    contact.save().then(
      () => console.log('Contact saved!', contact),
      (error: any) => console.error('Error saving contact.', error)
    );  

  }

that’s the error, the /ngx is missing, like you did in your app.module.ts

Hi @reedrichards,

i have changed and add ngx but now contact save but show blank. means name and number not showing on contact card.

1 Like

No idea. I just know why you where facing your original error

Same problem here :frowning:
I can’t set the name of a new contact…

same issues with contacts plugin :frowning: