Want a free Ebook & latest Update Subscribe Now
  [email protected]      beta
Donate

How to get client ip address in AngularJs

Code to Get IP Address: Here in this article will see how to get client IP address in AngularJs application. For this, we use angularjs $httpservice to make an ajax call, which in response gives us the Client IP AddressHostnameCity , RegionGeo Location (Latitude,Longitude) , Country  and name of organization and other details.

Basically, we call https://ipinfo.io/which displays IP Address.


Code to show client IP Address in Angularjs.

HTML Markup: Here added a span tag with an attributeng-bind with value as ip, which displays the IP address.

<body ng-app="myApp">
<body ng-app="myApp">
<div ng-controller="myip"> <span ng-bing="ip"></span>
</div> </body>

AngularJS Code: Here we use $http service to make an HTTP request, which in response gives the IP address and other information. The final code looks like as written below.

<script>
	var app = angular.module('myApp', []);
	app.controller('myip', function($scope, $http) {
		$http.get("https://ipinfo.io/").then(function (response) 
		{
			$scope.ip = response.data.ip;
		});
});
</script>

 

Conclusion: In Angularjs using $http service we call (https://ipinfo.io/) and get the client information. Here in $scope.ip  we have saved the client Ip Address.

Share:    
Satinder Singh

Hi all, am Founder and Author of Codepedia.info, also atypical polyglot programmer from Bombay, India. I have a passion to create, solve, and deploy software applications.
       ForEach ( minute in MyLife ) { myExperience++ ; }



Post Comment


Your email address will not be published. Required fields are marked *