import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Contacts,ContactField } from 'ionic-native';
/*
Generated class for the Addcontact page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Component({
selector: 'page-addcontact',
templateUrl: 'addcontact.html'
})
export class AddcontactPage {
newcontact: any;
constructor(private navCtrl: NavController) {
this.navCtrl = navCtrl;
this.newcontact = {
displayName: '',
nickname: '',
phnumber: '',
phtype: ''
}
}
addcontact(newct) {
let contact = Contacts.create();
contact.displayName = newct.displayName;
contact.nickname = newct.nickname;
let contactfield = new ContactField();
contactfield.type = newct.phtype;
contactfield.value = newct.phnumber;
contactfield.pref = true;
var numbersection = [];
numbersection.push(contactfield);
contact.phoneNumbers = numbersection;
contact.save().then((contact) => {
alert('saved');
}, (error) => {
alert(error);
})
}
}
trying to develop a contacts app with ionic 2 with contacts plugin i keep getting [ts]Left-hand side of assignment expression cannot be a constant or a readonly property
anyone with pointers i will appreciate
export declare class Contact implements IContactProperties {
private _objectInstance;
id: string;
displayName: string;
name: IContactName;
nickname: string;
phoneNumbers: IContactField[];
emails: IContactField[];
addresses: IContactAddress[];
ims: IContactField[];
organizations: IContactOrganization[];
birthday: Date;
note: string;
photos: IContactField[];
categories: IContactField[];
urls: IContactField[];
constructor();
clone(): Contact;
remove(): Promise;
save(): Promise;
}
sorry it the contacts.d.ts file
this is how i edited it by removing the readonly attribute i got it working
I hope so too, currently am trying to access the phone contact variables
like phone numbers and email but have not made much progress, do you have
any pointers?
my code <ion-list [hidden]="!search"> <ion-item *ngFor="let item of contactListArray ; let i = index"> <ion-avatar item-left> <img src="http://ionicframework.com/dist/preview-app/www/assets/img/avatar-finn.png"> </ion-avatar> <ion-label stacked>{{item.displayName}}</ion-label> <ion-input type="text" value="{{item.displayName}}"></ion-input> <p><strong>Phone(s)</strong></p> <ion-item *ngFor="let number of item.phoneNumbers; let j = index"> <p>{{ number.value }}</p> </ion-item> <p><strong>Email(s)</strong></p> <ion-item *ngFor="let email of item.emails; let k = index"> <p>{{ email.value }}</p> </ion-item> </ion-item> </ion-list>
contlist.ts
getContactList() {
let options = new ContactFindOptions();
options.filter = '';
options.multiple = true;
options.desiredFields = ['displayName', 'phoneNumbers', 'emails'];
options.hasPhoneNumber = true;
Contacts.find(['*'], options).then((contact) => {
this.contactListArray = contact;
console.log(this.contactListArray); // This shows the complete object.
//pushit to contact view point
}, (error) => {
let toast = this.toastCtrl.create({
message: 'Error Loading Contact List. Please Try Again',
duration: 3000,
position: 'bottom'
});
toast.present();
})
}
… Stay in eternity, Live in eternity, think differently, don’t get under
the pressure… http://goo.gl/Bggtzg