How to get current url path in Angularjs

How to get current url path in Angularjs

In this Post We Will Explain About is How to get current url path in Angularjs With Example and Demo.Welcome on Live24u.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Angularjs get current url path Example

In this post we will show you Best way to implement Angularjs get current url parameters, hear for Angular Get Current Route using the Location Service with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Also Read :   AngularJS Custom scrollbar Directive Example - ngscrollbar Example




Syntax of AngularJS $location Service

var app = angular.module('liveApp', []);
app.controller('live24uCtrl', function ($scope, $location) {
$scope.liveweburi = $location.absUrl();
});

AngularJS $location Example

<!DOCTYPE html>
<html>
<head>
<title>AngularJs Simple $location Service with Example</title>

<script src="1.4.8/angular.min.js"></script>

<script type="text/javascript">
var liveApp = angular.module('liveApp', []);
liveApp.controller('live24uCtrl', function ($scope, $location) {
$scope.liveweburi = $location.absUrl();
$scope.myhostname = $location.host();
$scope.webportno = $location.port();
$scope.livewebprotocol = $location.protocol();
});
</script>
</head>
<body>
<div ng-app="liveApp" ng-controller="live24uCtrl">
<p>AngularJs Url of Webpage: {{liveweburi}}</p>
<p>Host of Webpage in AngularJs: {{myhostname}}</p>
<p>AngularJs Port of Webpage: {{webportno}}</p>
<p>Angular Protocol of Webpage display: {{livewebprotocol}}</p>
</div>
</body>
</html>

index.js

This contains our simple custom index.js files Add Like as javascript, Angular scripts

var livebase = $location.absUrl().length - $location.url().length;
function getPath(fullUrl) { 
    return fullUrl.substring(livebase);
}

We can use simple $location.absUrl().

  $scope.$on('$locationChangeStart', function(e) {
      if (meetsTheRequirementsToLeave()) {
        return;
      }
      var livePath = $location.path();
      e.preventDefault();
      checkIfUserWantsToLeave().then(function() {
        $location.path(livePath);
      });
    });

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Also Read :   Angularjs Show Hide Password in Password TextBox with CheckBox





Example

I hope you have Got What is Angular Get Current Route using the Location Service And how it works.I would Like to have FeedBack From My Blog(live24u.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(live24u.com) Are Most Always Welcome.