{"id":12283,"date":"2016-05-05T16:15:06","date_gmt":"2016-05-05T13:15:06","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=12283"},"modified":"2017-12-19T16:28:48","modified_gmt":"2017-12-19T14:28:48","slug":"angular-js-location-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/","title":{"rendered":"Angular.js $location Example"},"content":{"rendered":"<p>One of the scenarios that you may have encountered while using AngularJS in your project is having to use the current URL of the website. It becomes especially important when you have to do routing or when the current URL is crucial to the well-functioning of your web-app. There&#8217;s an AngularJS service we use whenever we have to deal with these cases: <code>$location<\/code>. Below, you can read about how you can use it too!<\/p>\n<h2>1. What is <em>$location<\/em>?<\/h2>\n<p><code>$location<\/code> is an Angular service which enables you to have the URL in the browser&#8217;s address bar parsed and made available for use in your application. From there you can go on to use it however you wish, be it changing it, or using it to refresh your page (this you&#8217;d have to do manually). The changes that are made on the URL directly from the address bar will be immediately reflected into your <code>$location<\/code>, and similarly the changes you&#8217;d perform on the <code>$location<\/code> will be made visible into the address bar of the browser you&#8217;re using.<br \/>\n[ulp id=&#8217;LXJcMJZXSsqGXYW8&#8242;]<\/p>\n<h3>1.1 <em>$location<\/em> functions<\/h3>\n<p>The <code>$location<\/code> service has a number of functions which serve to define this service as much as make itself useful in many ways related to URLs. One of these functions, as mentioned briefly before, is the ability to expose the current URL found on the address bar, so that you can either watch or change it, depending on what your application requires.<\/p>\n<p>The second function is providing you with a &#8220;live communication channel&#8221; with the address bar. That consists of a synchronization between <code>$location<\/code> and the address bar that reflects all the changes in a two-directional manner whenever you change the URL directly from the address bar, click on a forward or backwards button in the browser, click on a history link or another random one in the page you&#8217;re currently viewing.<\/p>\n<p>Another very important function of the service is enabling us to view the URL we&#8217;re getting not only as a simple object but as a set of methods. You have a URL in your hands? That translates to having a full set of methods such as protocol, host, port, path, search and hash. That would make it much more easier for you to understand and modify the URL you&#8217;re getting. Handy, right?<\/p>\n<h3>1.2 <em>$location<\/em> vs. <em>window.location<\/em><\/h3>\n<p>If you already know what <code>window.location<\/code> does, and are just now being presented to <code>$location<\/code> you might be asking yourself: are they the same thing? Well no, however their purpose is the same: to allow reading or writing the browser&#8217;s current location. What are some other similarities and differences between them?<\/p>\n<p>Regarding the similarities, I&#8217;d say that is about it: they have the same purpose (and to be fair <code>$location<\/code> is based on <code>window.location<\/code> on that one) but are different in how they approach bringing that purpose to fruition.<\/p>\n<p>That would mean we would have an impressive number of differences between the two. The first one of the bunch would be the API approach. While <code>window.location<\/code> would return a straightforward object with all it&#8217;s properties and methods and whatnot (which can also be modified directly), <code>$location<\/code> would return getters and setters, similar to jQuery.<\/p>\n<p>The next aspect to consider would be the integration. <code>window.location<\/code> cannot be integrated with neither the Angular application life-cycle, nor the HTML5 API. That would be pretty easy for $location, which can do both, and seamlessly at that.<\/p>\n<p>The last difference would be in whether they have awareness of the context from which the document is loaded or not. Can you guess which has this and which not? If you guessed <code>$location<\/code> would win this round too, then you were completely right! While <code>window.location.pathname<\/code> would include the docroot in the result it&#8217;s give to us, it&#8217;s colleague from the other company would just return the actual path from which the document was loaded. Time to upgrade!<\/p>\n<h2>2. Configuration<\/h2>\n<p>The <code>$location<\/code> service works differently based on what configuration it&#8217;s currently using. Yes, you have to configure it before using it! For some applications the default configuration is more profitable, for others you have to change it in order to get new features made available to you. Once you have the configuration instantiated you can interact with the <code>$location<\/code> using the getter and setter methods that come with it, which we will get to discussing a bit later.<\/p>\n<h3>2.1 The <em>$locationProvider<\/em><\/h3>\n<p>There are two configuration modes that you can use: the Hashbang mode and the HTML5 mode. Before explaining each of them we&#8217;ll first take a look at one crucial element that we&#8217;ll use to configure our <code>$location<\/code>. That would be the <code>$locationProvider<\/code>.<\/p>\n<p><code>$locationProvider<\/code> is a provider in the ng module that is used to configure how the application&#8217;s deep linking paths are stored. It has only two methods which are used to set the parameters as we want them: <code>html5Mode()<\/code> and <code>hashPrefix()<\/code>.<\/p>\n<p>The first one, <code>html5Mode()<\/code>, is a boolean value or object that takes only one parameter which would define the mode we want to use on our <code>$location<\/code>. This parameter can be either <code>TRUE<\/code> in case you want to use the HTML5 mode, <code>FALSE<\/code> in case you want to use the Hashbang mode which is also the default one, or <code>requireBase:true<\/code> to see relative links.<\/p>\n<p>The second method, <code>hashPrefix()<\/code>, is only used in Hashbang mode or in legacy browser for the HTML5 mode. It takes only one argument which would be the prefix that will be used for Hashbang URLs.<\/p>\n<p>The syntax for the configuration is fairly simple and would look a lot like the code snippet below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>syntax.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">$locationProvider.html5Mode(true).hashPrefix('*');\r\n<\/pre>\n<p>What we&#8217;ve done here is just invoke the methods mentioned above by using the dot operator to link them with the <code>$locationProvider<\/code>. Still, you might be unclear, since we never clarified what each of the configuration modes meant, but we&#8217;ll clarify that on their own time.<\/p>\n<h3>2.2 Getters and Setters<\/h3>\n<p>We mentioned that after configuring the <code>$location<\/code> on the mode in which you want to work on, there is one way through which you can communicate and interact with it. That would be getter and setter methods. But what are these methods?<\/p>\n<p>The getter methods are used for the read-only parts of the url. There are four getter methods:<\/p>\n<ul>\n<li><code>absUrl()<\/code> &#8211; returns a full URL representation with all segments encoded according to rules specified in RFC 3986.<\/li>\n<li><code>protocol()<\/code> &#8211; returns the protocol of the current URL.<\/li>\n<li><code>host()<\/code> &#8211; returns the host of the current URL.<\/li>\n<li><code>port()<\/code> &#8211; returns the port of the current URL<\/li>\n<\/ul>\n<p>With that we get on the the methods that are both getters and setters. Those would be:<\/p>\n<ul>\n<li><code>url()<\/code> &#8211; it has only one optional parameter. When this parameter is omitted, the method returns the URL, and you can use it to change the path, search and URL when you give it an argument (which would be a URL in itself). Understandably, the method would return <code>$location<\/code>.<\/li>\n<li><code>path()<\/code> &#8211; is a method that would give us the path of the current URL when invoked without any argument, and change that path if it does take one as a parameter. Note that if you pass a path as a parameter, you have to start it with a forward slash [\/], so that the method can add it in case it is missing.<\/li>\n<li><code>search()<\/code> &#8211; is another method doubling both as a getter and a setter. If it&#8217;s used without any arguments it will return the search part of the URL as an object. However, if you want to use this method to set the search part of the URL, you would have to pass it two parameters: the first one would be the part you want replaced, and the second one would be what you want it replaced with.<\/li>\n<li><code>hash()<\/code> &#8211; is a method that gives us the hash part of the URL when called without an argument, and changes that fragment when called with a parameter.<\/li>\n<li><code>state()<\/code> &#8211; will return the history state object when called without any parameters and change that object when called with a parameter. Note that this method is valid only on HTML5 mode.<\/li>\n<\/ul>\n<p>That&#8217;s about it.<\/p>\n<h2>3. Configuration Modes<\/h2>\n<p>We mentioned before that there are two modes of configuration for the <code>$location<\/code> service: the Hashbang mode and the HTML5 mode. Applications use the same API in both modes, which means you can use whichever mode you want, according to your own needs and wants related to changes of the URL and browser history management.<\/p>\n<p>The best way to illustrate the difference between these two modes is by taking a URL and analyzing it in detail. Let us suppose we have the URL below:<\/p>\n<ul>\n<li><strong>http:\/\/website.com:9090\/#!\/mypath?param1=value1#hashvalue<\/strong><\/li>\n<\/ul>\n<p>Let&#8217;s start taking it apart piece by piece. You will see <code>http<\/code> first, which is the protocol that the URL uses. You see it in almost all the URLs you visit on the internet, as it&#8217;s one of the most used ones. It&#8217;s name is an acronym that stands for &#8220;HyperText Transfer Protocol&#8221;.<\/p>\n<p>Next up is <code>website.com<\/code> which would be the domain of your website. It&#8217;s followed closely by the port number which in our case is <code>9090<\/code> but could be another number such as <code>8080<\/code> or <code>3306<\/code>.<\/p>\n<p>Now you&#8217;ll see the element that differentiates a URL using Hashbang mode from one using HTML5 mode. It&#8217;s <code>#!<\/code> in our example, but could be <code>#*<\/code> or something else based on the <code>hashPrefix<\/code> that you have used in the configuration.<\/p>\n<p>Next, there are three elements which we can get for each URL by using the getters and setters: the <code>path<\/code>, the <code>search<\/code> and the <code>hash<\/code> part, respectively <code>\/mypath<\/code>, <code>param1=value1<\/code> and <code>hashvalue<\/code>.<\/p>\n<p>The same URL but using HTML5 mode would look like this:<\/p>\n<ul>\n<li><strong>http:\/\/website.com:9090\/mypath?param1=value1#hashvalue<\/strong><\/li>\n<\/ul>\n<p>But let&#8217;s delve more into each mode and see how can we configure and interact with each one.<\/p>\n<h2>4. Hashbang Mode<\/h2>\n<p>The Hashbang mode can be applied either by configuring your app to use that one specifically or even just not configuring it at all, since it&#8217;s the default configuration of the <code>$location<\/code> service. That wold mean that all the browsers are obliged to use the Hashbang URLs.<\/p>\n<p>This mode does not require server-side configuration, and it also does not allow the links to be intercepted and rewritten, as they work as expected. The configuration for this mode could be like below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>config.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">function($locationProvider) {\r\n    $locationProvider.html5Mode(false);\r\n    $locationProvider.hashPrefix('!');\r\n  }\r\n<\/pre>\n<p>As stated previously, that would be done by giving the necessary parameters to the methods <code>html5Mode()<\/code> and <code>hashPrefix()<\/code> of the <code>$locationProvider<\/code>. Below you&#8217;ll see an example of how easily you can communicate with the address bar regarding the URL:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>example.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">function($location) {\r\n    $location.absUrl() == 'http:\/\/website.com:9090\/#!\/mypath'\r\n    $location.path() == '\/mypath'\r\n    $location.protocol() == 'http'\r\n\r\n    $location.path('\/foo')\r\n    $location.absUrl() == 'http:\/\/website.com:9090\/#!\/foo'\r\n\r\n    $location.search() == {}\r\n    $location.search({a: 'b', c: true});\r\n    $location.absUrl() == 'http:\/\/website.com:9090\/#!\/foo?a=b&amp;c'\r\n\r\n    $location.path('\/new').search('x=y');\r\n    $location.absUrl() == 'http:\/\/website.com:9090\/#!\/new?x=y'\r\n  }\r\n<\/pre>\n<p>We used the same URL as the one in the illustration, so that you are as clear as possible on this. First of all, we used the getters <code>path()<\/code> and <code>protocol()<\/code>. You can already predict their result. Then you can see how does the usage of the setters affect the URL. Easy, right? Let&#8217;s see how is this different than the HTML5 mode.<\/p>\n<h2>5. HTML5 Mode<\/h2>\n<p>The HTML5 mode is based on the HTML5 API so that means all the getters and setters will interact with the URL through the HTML5 history API which would mean that the URL would use regular path and search segments, to counter it&#8217;s Hashbang counterparts.<\/p>\n<p>To use this mode you will have to configure it, and beware that while it will work correctly on new browsers, old browsers will fallback on the Hashbang mode. As you can see for yourself, the $location service uses the best mode available, and you would not have to worry if the browser supports the HTML5 history API or not and just code on.<\/p>\n<p>Differently from the Hashbang mode, this one allows interception and rewriting and also requires some server-side configuration. While in Hashbang mode the page would be reloaded automatically after each modification except for the hash fragment, that never happens with HTML5 mode.<\/p>\n<p>Let&#8217;s see how the configuration code snippet would look like:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>config.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">function($locationProvider) {\r\n    $locationProvider.html5Mode(true);\r\n    $locationProvider.hashPrefix('!');\r\n  }\r\n<\/pre>\n<p>It&#8217;s pretty simple, the only thing that changes from the previous configuration is the argument passed to the <code>html5Mode()<\/code> method of the <code>$locationProvider<\/code>. However, the thing that might confuse you would be the usage of <code>hashPrefix()<\/code> since we&#8217;ve already established that it&#8217;s only needed for Hashbang mode. The reason we do specify it is because our user will need it in case it&#8217;s browser doesn&#8217;t have the support for the HTML5 history API.<\/p>\n<p>Let&#8217;s see how the example we used in the section above would change now that we are using a different configuration mode:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>example.js<\/em><\/span><\/p>\n<pre class=\"brush:js\">function($location) {\r\n    $location.absUrl() == 'http:\/\/website.com:9090\/mypath'\r\n    $location.path() == '\/mypath'\r\n\r\n    $location.path('\/foo');\r\n    $location.absUrl() == 'http:\/\/website.com:9090\/foo'\r\n\r\n    $location.search() == {}\r\n    $location.search({a: 'b', c: true});\r\n    $location.absUrl() == 'http:\/\/website.com:9090\/foo?a=b&amp;c'\r\n\r\n    $location.path('\/new').search('x=y');\r\n    $location.url() == 'new?x=y'\r\n    $location.absUrl() == 'http:\/\/website.com:9090\/new?x=y'\r\n  }\r\n<\/pre>\n<p>As you see, the differences are close to none. In fact, you might not even notice it at all, it&#8217;s that small. To do that, you have to focus on the URL we&#8217;re using all along. It doesn&#8217;t contain the element <code>#!<\/code> that would mark it as a Hashbang URL.<\/p>\n<p>With that, you&#8217;re done and ready to use <code>$location<\/code> to your liking.<\/p>\n<h2>6. Download the source code<\/h2>\n<p>This was an example of $location in AngularJS.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <strong><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/location.zip\">$location<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>One of the scenarios that you may have encountered while using AngularJS in your project is having to use the current URL of the website. It becomes especially important when you have to do routing or when the current URL is crucial to the well-functioning of your web-app. There&#8217;s an AngularJS service we use whenever &hellip;<\/p>\n","protected":false},"author":25,"featured_media":909,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-12283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angular-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Angular.js $location Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"One of the scenarios that you may have encountered while using AngularJS in your project is having to use the current URL of the website. It becomes\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Angular.js $location Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"One of the scenarios that you may have encountered while using AngularJS in your project is having to use the current URL of the website. It becomes\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/era.balliu.7\" \/>\n<meta property=\"article:published_time\" content=\"2016-05-05T13:15:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-19T14:28:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Era Balliu\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@BalliuEra\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Era Balliu\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/\"},\"author\":{\"name\":\"Era Balliu\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/c27ecf40c810e6396ba93ffb829c7b0e\"},\"headline\":\"Angular.js $location Example\",\"datePublished\":\"2016-05-05T13:15:06+00:00\",\"dateModified\":\"2017-12-19T14:28:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/\"},\"wordCount\":2156,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"articleSection\":[\"Angular.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/\",\"name\":\"Angular.js $location Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"datePublished\":\"2016-05-05T13:15:06+00:00\",\"dateModified\":\"2017-12-19T14:28:48+00:00\",\"description\":\"One of the scenarios that you may have encountered while using AngularJS in your project is having to use the current URL of the website. It becomes\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Angular.js\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/angular-js\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Angular.js $location Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/c27ecf40c810e6396ba93ffb829c7b0e\",\"name\":\"Era Balliu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f6adddf7eada210f682608fea9d8159441369ec622998a5851a447e0a2bfa3f3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f6adddf7eada210f682608fea9d8159441369ec622998a5851a447e0a2bfa3f3?s=96&d=mm&r=g\",\"caption\":\"Era Balliu\"},\"description\":\"Era is a Telecommunications Engineering student, with a great passion for new technologies. Up until now she has been coding with HTML\/CSS, Bootstrap and other front-end coding languages and frameworks, and her recent love is Angular JS.\",\"sameAs\":[\"http:\/\/www.webcodegeeks.com\/\",\"https:\/\/www.facebook.com\/era.balliu.7\",\"https:\/\/www.instagram.com\/eraballiu\/\",\"https:\/\/www.linkedin.com\/in\/eraballiu\",\"https:\/\/www.pinterest.com\/001r2gw0jt0ln6d\/\",\"https:\/\/x.com\/BalliuEra\",\"https:\/\/www.youtube.com\/c\/eraballiu\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/era-balliu\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Angular.js $location Example - Web Code Geeks - 2026","description":"One of the scenarios that you may have encountered while using AngularJS in your project is having to use the current URL of the website. It becomes","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/","og_locale":"en_US","og_type":"article","og_title":"Angular.js $location Example - Web Code Geeks - 2026","og_description":"One of the scenarios that you may have encountered while using AngularJS in your project is having to use the current URL of the website. It becomes","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/era.balliu.7","article_published_time":"2016-05-05T13:15:06+00:00","article_modified_time":"2017-12-19T14:28:48+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","type":"image\/jpeg"}],"author":"Era Balliu","twitter_card":"summary_large_image","twitter_creator":"@BalliuEra","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Era Balliu","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/"},"author":{"name":"Era Balliu","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/c27ecf40c810e6396ba93ffb829c7b0e"},"headline":"Angular.js $location Example","datePublished":"2016-05-05T13:15:06+00:00","dateModified":"2017-12-19T14:28:48+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/"},"wordCount":2156,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","articleSection":["Angular.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/","name":"Angular.js $location Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","datePublished":"2016-05-05T13:15:06+00:00","dateModified":"2017-12-19T14:28:48+00:00","description":"One of the scenarios that you may have encountered while using AngularJS in your project is having to use the current URL of the website. It becomes","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-location-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"Angular.js","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/angular-js\/"},{"@type":"ListItem","position":4,"name":"Angular.js $location Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/c27ecf40c810e6396ba93ffb829c7b0e","name":"Era Balliu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f6adddf7eada210f682608fea9d8159441369ec622998a5851a447e0a2bfa3f3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f6adddf7eada210f682608fea9d8159441369ec622998a5851a447e0a2bfa3f3?s=96&d=mm&r=g","caption":"Era Balliu"},"description":"Era is a Telecommunications Engineering student, with a great passion for new technologies. Up until now she has been coding with HTML\/CSS, Bootstrap and other front-end coding languages and frameworks, and her recent love is Angular JS.","sameAs":["http:\/\/www.webcodegeeks.com\/","https:\/\/www.facebook.com\/era.balliu.7","https:\/\/www.instagram.com\/eraballiu\/","https:\/\/www.linkedin.com\/in\/eraballiu","https:\/\/www.pinterest.com\/001r2gw0jt0ln6d\/","https:\/\/x.com\/BalliuEra","https:\/\/www.youtube.com\/c\/eraballiu"],"url":"https:\/\/www.webcodegeeks.com\/author\/era-balliu\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/12283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=12283"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/12283\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/909"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=12283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=12283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=12283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}