My current url is http://localhost:4200/test/dashboard.
I want to print base url i.e http://localhost:4200 using angular 5 features.
You can Try (Can Get all Detail of current location)
import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common';
@Component({
selector: 'some-component',
templateUrl: './component.html',
styleUrls: ['./component.scss']
})
export class SomeComponent implements OnInit {
constructor(location: Location) {}
ngOnInit() {
console.log(this.location._platformStrategy._platformLocation.location);
}
}