Location.origin to get base hostname inside Factory


We need location.origin to get absolute path for location of assets.

For example when using ngx-translate:

export function TranslateFactory(http: HttpClient): TranslateHttpLoader {
    return new TranslateHttpLoader(http, location.origin + '/assets/i18n/', '.json');

The need for location.origin is necessitated due to an update in angular2-jwt where relative URLs are no longer supported and an absolute URL is required:
Angular2 JWT absolute URL


Looking at code inside NativeScriptHttpClientModule, the first character of url is looked, if it matches / or ~ then the URL is considered a local file, otherwise the http request is sent.

So the code is currently working with HttpClient, angular2-jwt and ngx-translate.

However, I’ll keep the question open since it might be useful to see if there is a mechanism available to get location.origin for other use-cases.