Reputation: 69
I'm trying to get the domain with the Router
through ActivatedRouter
but I can't get the domain.
Is there a way to get the domain name from one of them?
Upvotes: 2
Views: 10453
Reputation: 11
You can try and use plain javascript create a variable and use below code
"window.location.hostname"
Upvotes: 0
Reputation: 86790
You can get full Location
object using the code, where you can find everything related to the router including hostname, URL, params etc -
constructor(@Inject(DOCUMENT) private document) {
console.log(document.location);
}
The object contains info -
{
"href": "http://localhost:4200/",
"ancestorOrigins": {},
"origin": "http://localhost:4200",
"protocol": "http:",
"host": "localhost:4200",
"hostname": "localhost",
"port": "4200",
"pathname": "/",
"search": "",
"hash": ""
}
window.location.href
Also, router
object from angular contains much information about router/navigation.
Upvotes: 13
Reputation: 2893
Give try on this below code
Create a Variable of Location Type
public location: Location
this.location['_platformStrategy']._platformLocation.location.host
Upvotes: 1