title: Javascript / Angular httpClient get data from url and pass outside method
body: <p>I am using angular 5 and I have installed the <strong><em>httpClient</em></strong> Module so I can get data from an api.</p>
  
  <p>On my app.component.ts I have this:</p>
  
  <pre><code>getData() {
      this.http.get('url to get xml data from', { responseType: 'text' }).subscribe(data =&gt; {
      return data;
   });
  }
  </code></pre>
  
  <p>What I need to do it to call this method from my ngOnInit so that I can use the data outside the method so I tried this:</p>
  
  <pre><code> ngOnInit() {
      this.result = this.getData();
  }
  </code></pre>
  
  <p>But the above is not giving me the data so what I'm I missing for this to work with Angular?</p>