title: Display a contact list with Ionic + Cordova + AngularJS without using ng-click
body: <p>I am trying to display my contact list on my smartphone. I can achieve this but the only way to ask for the list to display is to call the findcontact() function with a ng-click. </p>
  
  <p>I tried to call the findcontact() function from within the controller but with no luck.</p>
  
  <p>How can I display this list without having to click on this button ?</p>
  
  <p>First the javascript, then the HTML.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>angular.module('starter.controllers', [])
  
  .controller('contacts2', ['$scope', 'PhoneContactsFactory', function($scope, PhoneContactsFactory) {
      
   $scope.findContact = function()
      {
          PhoneContactsFactory.find().then(function(contacts)
          {
              $arr = [];
              for (var i = 0; i &lt; contacts.length; i++)
              {
      $arr.push({name: contacts[i].name.formatted})
     }
              $scope.contacts = $arr;
          });
    
      };
  }])
  
  .factory("PhoneContactsFactory", ['$q', function($q)
  {
      return {
          find: function()
          {
              var deferred = $q.defer(); // asynchronous
              var options = new ContactFindOptions();
              options.multiple = true;
              var fields = ["displayName", "name"];
              
              navigator.contacts.find(fields, 
      function(contacts){ deferred.resolve(contacts); }, //onsuccess
      function(error){ deferred.reject(error); }, // onerror
      options);
              return deferred.promise;
          }
   };
  }]);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div ng-controller="contacts2"&gt;
      &lt;button ng-click="findContact()"&gt;Push 2&lt;/button&gt;
   &lt;ion-list&gt;
       &lt;ion-item ng-repeat="contact in contacts"&gt;
         {{contact.name}}
       &lt;/ion-item&gt;
     &lt;/ion-list&gt;
   &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thanks a lot !</p>
  
  <p>yts</p>