0
$http.get('localhost:8080/myApp/Login).success(function() {.....
…..
…
});

I want to replace 'localhost:8080/myApp with the host where I will deploy my project with project name at that time …

What I am doing is that using angular I am mapping the URL to spring controller method . So I don't want it to be static I want 'localhost:8080/myApp to be taken dynamically where I am deploying my project with the project name …

While working Projects name: myApp Host:localhost:8080

When deployed Projects name: myApplication Host:www.xyz.com

So my $http.get('www.xyz.com/myApplication/Login). success(function(){... …. …});

Update:I also want my project name to be automatically taken in which my js and Java controller is there

Rohìt Jíndal
  • 16,572
  • 12
  • 64
  • 110
Aman
  • 196
  • 1
  • 2
  • 15
  • Don't hard code host names, rather use only the URIs in your JSP/HTML – developer Nov 14 '16 at 23:37
  • 1
    Possible duplicate of [How to change context root of a dynamic web project in Eclipse?](http://stackoverflow.com/questions/2437465/how-to-change-context-root-of-a-dynamic-web-project-in-eclipse) – developer Nov 14 '16 at 23:38

1 Answers1

1

The $location service does provide information from the url. So, you could construct something to then make the dynamic host:

// given URL http://example.com/#/some/path?foo=bar&baz=xoxo
var host = $location.host();
// => "example.com"

// given URL http://user:password@example.com:8080/#/some/path?foo=bar&baz=xoxo
host = $location.host();
// => "example.com"
host = location.host;
// => "example.com:8080"  

First you need to declare $location in your service then you can extract dynamic location host port.

To know more about $location service please check angular api doc

Extract Project Name:

For Extract Projet name i make my custom method which get project name from $location.absUrl() use Following function:

var url= $location.absUrl();
    url= getProjectName(url); 

function getProjectName(url){
            var index,int;
            for (int = 0; int <3; int++) {
                 index = url.indexOf("/");
                 url= url.substring(index+1);
            }
            var index = url.indexOf("/");
            url = url.slice(0, index);

            return url;
        }
Saurav Wahid
  • 371
  • 2
  • 8
  • I also want my project name to be automatically taken ...I.e the name of the project in which my Js , Java controller is there.. – Aman Nov 15 '16 at 06:10
  • I make custom method for extract project name from `$location.absUrl()` check on edit part answer – Saurav Wahid Nov 15 '16 at 09:38