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
See: http://www.w3schools.com/jsref/obj_location.asp
window.location.*** it is as mentioned above. Here's the visual representation of different location properties: http://bl.ocks.org/abernier/3070589
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With