Making ajax calls to third party APIs in ionic services.js file?
<p>Started using ionic today and ran into a small bump.
The services.js file has a comment
<code>// Might use a resource here that returns a JSON array</code></p>

<p>I want to make an ajax call to an API but I don't know how do declace a custom resource in that services.js file. 
I will receive a JSON array from that call and will work with the list thre on.</p>

<p>Question: How do I declare a custom variable as a list which makes an ajax call to a third pary API?</p>

<pre><code>angular.module('starter.services', [])

.factory('Chats', function() {
// Might use a resource here that returns a JSON array
 var popularURL = 'SOME_API_RUL';
 var xhttp = new XMLHttpRequest();
 xhttp.onreadystatechange = function() {
 if (xhttp.readyState == 4 &amp;&amp; xhttp.status == 200) {
    var chats = xhttp.responseText;
  }
};
xhttp.open("GET", popularURL, true);
xhttp.send();

return {
  all: function() {
    return chats;
  },
  remove: function(chat) {
    chats.splice(chats.indexOf(chat), 1);
  },
  get: function(chatId) {
  for (var i = 0; i &lt; chats.length; i++) {
    if (chats[i].id === parseInt(chatId)) {
      return chats[i];
    }
  }
  return null;
  }
};
</code></pre>

<p>The chats list is never populated. How do a correctly make an ajax call inside the ionic services.js file.</p>

<p>Thank you!</p>