How to get current URL Location in Angularjs?

March 26, 2018 | Category : Angular

Here, you will learn how to get current url, hostname, port number, protocol etc using $location variable in angularjs. i gave you full example of getting current full url with port number, protocol etc with angularjs, so just see bellow code how i write example.

we just create "HDTutoApp" app and "HDTutoCtrl" controller for example to getting current full path. So you need to just copy bellow code and run in your desk. So do it that.


<!DOCTYPE html>



<title>Get current url in Angularjs?</title>

<script src=""></script>



<div ng-app="HDTutoApp" ng-controller="HDTutoCtrl">

<p>AngularJs Url of Webpage: {{ weburi }}</p>

<p>Host of Webpage in AngularJs: {{ myhostname }}</p>

<p>AngularJs Port of Webpage: {{ webportno }}</p>

<p>Angular Protocol of Webpage display: {{ webprotocol }}</p>


<script type="text/javascript">

var HDTutoApp = angular.module('HDTutoApp', []);

HDTutoApp.controller('HDTutoCtrl', function ($scope, $location) {

$scope.weburi = $location.absUrl();

$scope.myhostname = $;

$scope.webportno = $location.port();

$scope.webprotocol = $location.protocol();





I hope you found your best solution....