My current url is http://localhost:4200/test/dashboard.
I want to print base url i.e http://localhost:4200 using angular 5 features.
import { DOCUMENT, LocationStrategy } from '@angular/common';
@Injectable()
export class SomeService {
constructor(@Inject(DOCUMENT) private readonly document: any,
private readonly locationStrategy: LocationStrategy) {}
// for localhost: http://localhost:4200/someBaseHref
getUrl(): string {
return `${this.document.location.origin}/${this.locationStrategy.getBaseHref()}`
}
}