Get Contact Details In Ionic
Hello friends, we all aware of the fact that we need a large market for any business if it would be soft business or digital marketing business. Whenever we create any site or any app we always try to make it popular by using advertisement or any other technique. But there is such a great technique, suppose you make an app and you want to send your app link details through the message to a million of public. And here you need so many contact numbers. So you can get it by your app. Just follow my steps to get contact details in ionic.
Step 1:
We will use Cordova contact plugins for this. Now, first of all, install ionic and set up a project on your pc. If you are a new comer in ionic platform then follow this link how to install ionic. Now you have your project ready.
Step 2:
Now you have to install the cordova contact plugin for getting contact details. So open your terminal or cmd and go your project directory in terminal or cmd. Now enter the bellow comand and hit enter.
cordova plugin add cordova-plugin-contacts
Now make a controller for applying your code. I have already a code & you can try this
MainController
angular.module('starter').controller('MainController', function($scope,$ionicPlatform,$cordovaContacts) { $scope.contacts = []; $ionicPlatform.ready(function() { $cordovaContacts.find([]).then(function(allContacts) { $scope.contacts = allContacts; }); }); });
Step 3:
Now create a related HTML template for its view page. I have already a code you can use it.
index.html
<body ng-app="starter" ng-controller="MainController"> <ion-pane> <ion-header-bar class="bar-stable"> <h1 class="title">Ionic Blank Starter</h1> </ion-header-bar> <ion-content> <div ng-repeat="data in contacts"> <p>{{data.phoneNumbers[0]["value"]}}</p> </div> </ion-content> </ion-pane> </body>
Now run this code and get the result on your mobile. If everything is right you can see all the contact number of your mobile.