Does anyone know how to get base url in Angular 4? For example: think I have that -> https://stackoverflow.com/questions/ask but I want to get only -> https://stackoverflow.com
I tried to get it like that :
constructor(private http: Http, private platformLocation: PlatformLocation) {
this.baseUrl = (platformLocation as any).location.origin;
}
But I got that error:
An unhandled exception occurred while processing the request.
NodeInvocationException: Cannot read property 'origin' of undefined
TypeError: Cannot read property 'origin' of undefined
at new AppSettingsService (D:\Projects\CH.AdminClient\CH.AdminClient\ClientApp\dist\main-server.js:3028:50)
at _createClass (D:\Projects\CH.AdminClient\CH.AdminClient\ClientApp\dist\vendor.js:20473:17)
at _createProviderInstance$1 (D:\Projects\CH.AdminClient\CH.AdminClient\ClientApp\dist\vendor.js:20441:26)
at initNgModule (D:\Projects\CH.AdminClient\CH.AdminClient\ClientApp\dist\vendor.js:20395:13)
at new NgModuleRef_ (D:\Projects\CH.AdminClient\CH.AdminClient\ClientApp\dist\vendor.js:21503:9)
at Object.createNgModuleRef (D:\Projects\CH.AdminClient\CH.AdminClient\ClientApp\dist\vendor.js:21487:12)
at NgModuleFactory_.module.exports.NgModuleFactory_.create (D:\Projects\CH.AdminClient\CH.AdminClient\ClientApp\dist\vendor.js:24768:25)
at D:\Projects\CH.AdminClient\CH.AdminClient\ClientApp\dist\vendor.js:15453:61
at ZoneDelegate.module.exports.ZoneDelegate.invoke (D:\Projects\CH.AdminClient\CH.AdminClient\ClientApp\dist\vendor.js:85786:26)
at Object.onInvoke (D:\Projects\CH.AdminClient\CH.AdminClient\ClientApp\dist\vendor.js:14830:37)
Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance+<InvokeExportAsync>d__7.MoveNext()