I need to get the current URL present in the browser in my Angular 2 application.
In JavaScript normally we do it using the window object.
How can I do this
It is not necessary to import complicated packages or inject something. Just use the methods you can find on window.location!
Such as:
window.location.href gives you the full URLwindow.location.hostname gives you the host namewindow.location.originwith this command you get the host name with protocol (e.g. https://)For IE<=10 users: location.origin may not be available, then you have to use
location.protocol + "//" + location.hostnameor use a polyfill or package like location-origin