Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the host in angular2

Tags:

angular

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?)

like image 377
Reinhard Avatar asked Oct 18 '25 17:10

Reinhard


2 Answers

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

like image 84
Shovalt Avatar answered Oct 20 '25 07:10

Shovalt


window.location.*** it is as mentioned above. Here's the visual representation of different location properties: http://bl.ocks.org/abernier/3070589

like image 35
rook Avatar answered Oct 20 '25 06:10

rook



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!