I want to get the base path of my Angular app.
Right now I'm doing this: $scope.baseUrl = '$location.host()
But I only get this: /localhost
. My current baseURL is http://localhost:9000/
.
An alternative answer is using the $window
service in conjunction with $location.absUrl()
to create a new URL object, and then grab the origin via the origin property. This will give you exactly what you're looking for (minus the trailing '/').
$scope.baseUrl = new $window.URL($location.absUrl()).origin;
will give you back http://localhost:9000 in your case.
Try this: $location.$$absUrl
console.log('$location',$location.$$absUrl);
btw /localhost
is your base path, but I guess you meant entire URL.
To get just the baseurl and nothing else use
$browser.baseHref()
it will return something like
/central/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With