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?

Samantha J T Star
  • 28,982
  • 82
  • 233
  • 406
  • 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 – callmekatootie Aug 03 '15 at 14:14

3 Answers3

4

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

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

more info in documentation

Domas Mar
  • 1,128
  • 1
  • 11
  • 23
3

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

var full = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');
Community
  • 1
  • 1
Johannes Ferner
  • 698
  • 6
  • 15
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

akashrajkn
  • 2,235
  • 2
  • 19
  • 46