VOOZH about

URL: https://www.geeksforgeeks.org/angular-js/how-to-get-the-current-url-using-angularjs/

⇱ How to get the current URL using AngularJS ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to get the current URL using AngularJS ?

Last Updated : 8 Nov, 2022

In this article, we will see how to get the current URL with the help of AngularJS, along with knowing its basic implementation through the examples. This task can be accomplished in 2 ways, i.e., by implementing the $location.absURL() method to get the complete URL of the current page, & the 2nd-way implements the split() method that is appended with the absURL() method to get the domain name of the URL. We will explore both approaches for getting the current URL using AngularJS.

$location.absURL() method: The $location service facilitates to parse of the URL in the address bar & makes the URL avail to an application. The absUrl() Method returns the full path of your page and it is a read-only method.

Syntax:

$location.absURL();

Example 1: in this example, we are using the $location.absURL() method to get the complete URL of the current page. 

Output:

👁 Image
 

split() method: This method can also be used to get the domain name of the URL by appending it after the absURL() method.

Example 2: Similar to the previous example but using the split() method to get the domain name of the URL.

Output:

👁 Image
 
Comment

Explore