I'm looking for a way to get the host of the current URL using Angular2. So on
http://example.com/myapp.html
I want to get:
example.com
(in angular1 I used $location.host() to parse it out. Is there something similar?)
I'm looking for a way to get the host of the current URL using Angular2. So on
http://example.com/myapp.html
I want to get:
example.com
(in angular1 I used $location.host() to parse it out. Is there something similar?)
Well, there's the old fashioned window.location JavaScript object. It has all of the elements that compose a url under it. Try printing it to the console to take a look:
console.log(window.location);
Edit:
What you actually need is window.location.host
window.location.*** it is as mentioned above. Here's the visual representation of different location properties: http://bl.ocks.org/abernier/3070589
location.hostname
For example, in your ts file, let x = //${location.hostname}
and in your browser you type: http://www.example.com
you get x="http://www.example.com"
then you get example from x should be easy.