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.
Index.html
<!DOCTYPE html>
<html>
<head>
<title>Get current url in Angularjs?</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.js"></script>
</head>
<body>
<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>
</div>
<script type="text/javascript">
var HDTutoApp = angular.module('HDTutoApp', []);
HDTutoApp.controller('HDTutoCtrl', function ($scope, $location) {
$scope.weburi = $location.absUrl();
$scope.myhostname = $location.host();
$scope.webportno = $location.port();
$scope.webprotocol = $location.protocol();
});
</script>
</body>
</html>
I hope you found your best solution....
Do you like below Tutorials ?
- Laravel 7.x and 6.x Ajax Multiple Image Upload with Preview Example
- Laravel select with count(*) using db raw example
- PHP Laravel select with join subquery example
- PHP Laravel Ajax Form Submit Example
- How to create events for created/updated/deleted model task in Laravel 5?
- Angular JS Form Validation Example Code
- AngularJS - Confirm Password Validation Example
- Laravel Ajax Request using X-editable bootstrap Plugin Example