title: Get local IP on angular2 component.ts
body: <p>I have a web app and an API inside a raspberry PI. The web app uses HTTP GET requisitions to the API to display its content</p>
  
  <p>Now, inside the web app component.ts:</p>
  
  <pre><code>export class AppComponent implements OnInit {
  
      results = {};
  
      constructor(private http: HttpClient) {}
      ngOnInit(): void {
  
          var url = 'http://localhost:8000/api/';
          var endpoint = 'test/';
  
          this.http.get(url + endpoint).subscribe(data =&gt; {
            this.results = data['test'];
          })
      }
  }
  </code></pre>
  
  <p>This works when I open the web app on a browser INSIDE the raspberry. 
  However, when opening the web app from another device using the raspberry's IP and the port the app is running, I can't get the data from the API. </p>
  
  <p>I assume it's because of the 'localhost', and once this rasp CANNOT BE SET WITH A STATIC IP I'd like to retrieve its local IP, to make something like: </p>
  
  <pre><code>    ngOnInit(): void {
  
          var ip = &lt;some code &lt;-- HELP&gt;
          var url = 'http://' + ip + ':8000/api/';
          var endpoint = 'test/';
  
          this.http.get(url + endpoint).subscribe(data =&gt; {
            this.results = data['test'];
          })
      }
  </code></pre>
  
  <p>And I've tested, if I put the IP manually in the code it works, though it was just for test, I don't want to input it manually.</p>