HI,
I have a function, that reads the phonebook. After getting the contacts, it should sort them.
The last time, I worked on my APP, it worked, now, it doesn’t.
This is my code:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Contacts } from '@ionic-native/contacts';
@IonicPage()
@Component({
selector: 'page-telefonbuch',
templateUrl: 'telefonbuch.html',
})
export class TelefonbuchPage {
entries : any
contacts1 = []
constructor(public navCtrl: NavController, public navParams: NavParams, private contacts: Contacts) {
this.contacts.find(["displayName", "phoneNumbers"], {multiple: true, hasPhoneNumber: true}).then((contacts) => {
for (var i=0 ; i < contacts.length; i++){
if(contacts[i].displayName !== null){
var obj = {};
obj["name"] = contacts[i].displayName;
obj["number"] = contacts[i].phoneNumbers[0].value;
this.contacts1.push(obj) // adding in separate array with keys: name, number
}
}
});
this.entries = this.contacts1;
}
compare(a,b) {
if (a.name < b.name)
return -1;
if (a.name > b.name)
return 1;
return 0;
}
ionViewDidLoad() {
this.entries.sort(this.compare);
}
}
Currently it does not return sorted contacts.
What is wrong with my code?
Many Thanks,
Lars