title: Ionic5 Angular - transform http reponse to custom object
body: <p>I'm completely new to Ionic and angular and I'm trying to load data from a REST api (for testing a local json file) and transform them to an object as the origin json structure is not really useful.</p>
  <p>I tried this:</p>
  <pre><code>ngAfterViewInit(){
    var data = this.locationService.getLocalData()
    console.log(data);
  }
  
  </code></pre>
  <p>location.service.ts:</p>
  <pre><code>getLocalData() {
  let url = &quot;/assets/data/locallocations.json&quot;;
   this.http.get&lt;any[]&gt;(url).subscribe(result =&gt; {
    var locations: Array&lt;Location&gt; = [];
        result.forEach(element =&gt; {
          try {
            var location: Location = new Location;
            location.id = element.station[&quot;id&quot;];
            location.name = element.station[&quot;name&quot;];
            location.number = element.station[&quot;number&quot;];
            location.longitude = element.station[&quot;geocoordinate&quot;][&quot;longitude&quot;];
            location.latitude = element.station[&quot;geocoordinate&quot;][&quot;latitude&quot;];
            locations.push(location);
            
          } catch(error){
          }
        })
        console.log(locations)
      return locations
  
  });
  }
  </code></pre>
  <p>in the ngAfterViewInit() the console log is always undefinied (but not in the getLocalData()) - could somebody help me creating the getLocalData function in a way that I can also subscribe on it and wait for the result? Thanks.</p>