I need to get base URL using angular.js
Can any one help me on this?
I tried with different solutions and but I am not getting proper URL.
The angular way of getting the url is using the $location service. You need to inject it wherever you need it (controller, another service, etc...)
angular
.module('app')
.controller('controller', mainController);
/** @ngInject **/
function mainController($location){
console.log($location) //prints all $location properties
console.log($location.$$host) // prints 'stackoverflow.com'
console.log($location.$$absUrl) // prints 'http://stackoverflow.com/exampleurl'
}
You can do it the non-angular way, using the global window.location object:
console.log(location.href) // prints 'http://stackoverflow.com/exampleurl'
Hope it helps
If you want to get the base URL in the browser using Javascript you can use:
window.location.origin
Or to get an object of all parts use:
window.location
Hope this helps :)
$locationinto your controller? Tried$location.$$absUrl?