Angularjs get current url


Angularjs get current url : We sometimes need to get the current url in AngularJs. It is very easy and simple to get the current Url in AngularJs. $locaction.absUrl() is used to get the current Url. Here in this tutorial we are going to explain how you can get the current url in AngularJs. You can use our online editor to edit and run the example.


Angularjs get current url | Full url

You can use the $locaction.absUrl() method to get the current Url. This will give you the full url including the query strings. Here we have created a simple function to use this method and get the current url.

Angularjs get current url Example:

 <script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope,$location) {
$scope.url = '';
$scope.currentUrl = function() {
	 $scope.url = $location.absUrl();
};
});
</script>

Try it »

The above function will give you the full url example –www.example.com?q=abc&r=ghd. You can use this function as per your need.

If you run the above example it will produce output something like this –

Angularjs get current url


Advertisements

Add Comment

📖 Read More