Wednesday, June 27, 2018

BASE_URL

Something from "ASP.NET Core 2 and Angular 5" by Valerio De Sanctis...

constructor(@Inject('BASE_URL') base: string) {

 
 

This at the constructor of an Angular 5 component allows you to turn around and use it in an HttpClient implementation like so:

this.http.get<Foo[]>(base + "api/foo").subscribe(result => {
   this.foo = result;
}, error => console.error(error));

 
 

This kinda assumes that the Angular stuff and the C# API have the same root URL as perhaps in a canned Visual Studio Angular application.

No comments:

Post a Comment