Try to first install nativescript-contacts and nativescript-permissions plugin for get contact list with set permission for contacts read, edit and add permission.
Set permission in
App_Resources->Android->src->main->Androidmanifest.xml File
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
contact.component.html:-
<ListView row="0" [items]="contactList" separatorColor="transparent">
<ng-template let-contact="item" let-i="index">
<GridLayout rows="*, auto" columns="auto, *, auto">
<Image col="0" *ngIf="contact && contact.photo" class="site-template-image" stretch="aspectFill" [src]="contact ? contact.photo : '~/app/images/avatar.jpg'"></Image>
<StackLayout col="0" class="site-template-first-icon" verticalAlignment="center">
<Label col="0" *ngIf="contact && contact.photo == null" horizontalAlignment="center" fontSize="24" color="#fff" [text]="contact && contact.name.displayname ? contact.name.displayname.charAt(0) : 'N/A'"></Label>
</StackLayout>
<StackLayout col="1" verticalAlignment="center">
<Label class="site-template-title" [text]="contact ? contact.name.displayname:'No data'"></Label>
<WrapLayout orientation="horizontal" *ngIf="contact && contact.phoneNumbers.length > 0">
<Label class="site-template-description" *ngFor="let phoneNumber of contact.phoneNumbers" text="{{phoneNumber.value + ' '}}"></Label>
</WrapLayout>
</StackLayout>
<StackLayout margin="0,16,0,35" row="1" colSpan="2" backgroundColor="lightGray" height="0.3"></StackLayout>
</GridLayout>
</ng-template>
</ListView>
contact.component.ts
import * as contacts from "nativescript-contacts";
import * as permissions from "nativescript-permissions";
declare var android;
@Component({
selector: "Contact",
moduleId: module.id,
templateUrl: "./contact.component.html",
styleUrls: ["./contact.component.css"]
})
export class HomeComponent implements OnInit {
public contactList: any;
constructor() { }
ngOnInit(): void {
// Init your component properties here.
this.getContactList();
}
getContactList() {
permissions.requestPermissions([android.Manifest.permission.GET_ACCOUNTS, android.Manifest.permission.READ_CONTACTS, android.Manifest.permission.WRITE_CONTACTS], "I need these permissions.")
.then(() => {
let contactFields = ["name", "phoneNumbers"];
contacts.getAllContacts(contactFields).then(
(data) => {
if (data.data.length > 0) {
this.contactList = data.data;
}
}, (err) => {
console.log("Error: " + err);
this.isLoading = false;
}
);
});
}
}