2016-09-19 157 views
1

我必須使用Ionic2保存聯繫人,但是當我使用cmd運行應用程序時出現錯誤。我已經安裝了cordova-plugin-contacts錯誤:connot找到名稱'ContactField'in ionic 2

這裏是我的代碼

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); 
    }) 
    } 
} 

之後,我得到這個錯誤

enter image description here

回答

1

你只需要導入它是這樣的:

import { Contact, ContactField } from 'ionic-native'; 
相關問題