Last active
July 21, 2020 18:39
-
-
Save akleemans/14c851b887dea01023f5c952d5418e63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component, OnInit} from '@angular/core'; | |
import {HttpClient} from "@angular/common/http"; | |
@Component({ | |
selector: 'app-root', | |
template: 'Called API and got: "{{greeting}}"' | |
}) | |
export class AppComponent implements OnInit { | |
public greeting: string; | |
public constructor(private readonly http: HttpClient) { | |
} | |
public async ngOnInit(): Promise<void> { | |
// Check if development or prod deployment | |
let restUrl = location.origin + '/api/hello?name=Azure'; | |
if (this.isDevelopment()) { | |
restUrl = 'http://localhost:8080/api/hello?name=Angular'; | |
} | |
this.greeting = await this.http.get(restUrl, {responseType: 'text'}).toPromise(); | |
} | |
private isDevelopment = (): boolean => location.host.includes('localhost'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment