1

I am using Angularjs and ui-router. In my application I have an email feedback form and the email text will contain the URL of the application. But when I run the application this could be:

localhost:1828 or the www.domain.name

Is there a way in my application that I could get the URL and the port so I could add this into the email?

1
  • 1
    Yes you can. However, this is more a back end than a front end feature - you don't want somebody to fake the URL if you do it from the client side. Thus - which backend are you using? Update the tag with that backend Commented Aug 3, 2015 at 14:14

3 Answers 3

4

You can inject $location service to your controller/service. And use like this:

$location.port();
$location.host();

more info in documentation

3

copied from: Get protocol, domain, and port from URL

var full = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');
1

Since you are using ui-router, you can use the $stateParams and $stateProvider to get the current url. See this for more information.

You can also use the URL Parameters feature to get the current url

Not the answer you're looking for? Browse other questions tagged or ask your own question.