Angular save http.data to array
<p>I'm trying to save my data comming from a $http request to an array. So I haven't call the api each time I need this list.</p>

<p>For now I have a service looking like this: </p>

<pre><code>angular.module('schwimmfestivalApp')
  .service('httpService', function($http) {
    // AngularJS will instantiate a singleton by calling "new" on this function
    var articleList = [];
    var food = [];


    this.getArticles = function() {
      if (articleList &lt; 1) {
        $http.get('https://www.anmeldung.schwimmfestival.de/server/func/getArtikel.php').then(response =&gt; {
          articleList = response.data;
          console.log(articleList);
        });
      }
      return articleList;
    };

    this.getArticleByCategory = function(category) {
      if (food.length &lt; 1) {
        for (var i = 0; i &lt; this.getArticles().length; i++) {
          if (this.getArticles()[i].kategorie == category) {
            food.push(this.getArticles()[i]);
          }
        }
      }

      return food;
    };

    this.getFood = function() {
      console.log('Food: '+ food);
      return this.getArticleByCategory('TN Essen')
    };
  });
</code></pre>

<p>I read something about async calls and so my code will go on before the array is filled.
Can you help me how to build this service so I can work with this array ? </p>

<p>Thanks in advance </p>