title: ionic / angular 8 ERROR TypeError: this.sendData is not a function
body: <p>Here is my code. I am simply trying to do a GET to a localserver and take the response (which is a JSON object) and send it to a different angular component.
  For some reason it is saying ERROR TypeError: this.sendData is not a function</p>
  
  <pre><code>import { HttpClient, HttpHeaders } from '@angular/common/http';
  import { Injectable } from '@angular/core';
  import { Subject } from 'rxjs';
  
  interface myData {
      data: Object
  }
  
  @Injectable({
      providedIn: 'root'
  })
  export class ApiService {
  
      goldProducts: any[] = [];
      httpOptions: any;
  
      constructor(private http: HttpClient) {}
      base_path = 'http://localhost:80';
  
      shareData = new Subject&lt;any&gt;();
  
      sendData(data: any) {
          this.shareData.next(data);
      }
  
      getGoldProducts() {
          this.httpOptions = {
              headers: new HttpHeaders({
                  'Content-Type': 'application/json',
  
              })
          }
          return this.http.get&lt;myData&gt;(this.base_path + '/get/goldProducts', this.httpOptions).subscribe(function(res) {
              console.log(res);
              this.sendData(res);
          });
      }
  }
  </code></pre>
  
  <p>and the component it is going to is:</p>
  
  <pre><code>import { Component } from '@angular/core';
  import { HttpClientModule } from '@angular/common/http';
  import { ApiService } from '../services/api.service';
  
  @Component({
    selector: 'app-home',
    templateUrl: 'home.page.html',
    styleUrls: ['home.page.scss'],
  })
  export class HomePage {
      goldProducts: any[] = [];
  
      getItemPrices: any[] = [];
      constructor(public api: ApiService, public http: HttpClientModule) { }
  
      displayGoldProducts() {
         this.api.shareData.subscribe(data =&gt; {
             console.log(data);
         });
         this.api.getGoldProducts();
      }
  }
  </code></pre>
  
  <p>the function displayGoldProducts() is simply hooked up to a button in the html.
  I will get the correct console log of the response but only from the api.service.
  I am at a loss on how to hook this up. I just want an observable so when I push new data  which are new prices from the server then the prices on the client will automatically update. Something simple to do in javascript but apparently a pain to do so far in angular. I am learning angular and the tutorials seem to cover different use cases. Any help would be appreciated and is probably just a formatting issue. Thankyou in advance.</p>