[email protected]      beta
Donate

How to get client ip address in AngularJs

Get IP Address : Here in this article will see how to get client IP address in angularjs. We use angularjs $http service to make a ajax call, which in response gives us the Client IP Address, Hostname, City , Region, Country, Location ( Latitude, Longitude) and name of organisation. 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 ng-bind attribute with value as ip, which display the IP address.

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

AngularJS Code: Here we use $http service to make a http request, which in response gives the IP addres and other information.

<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>

  Popular Tag
  Recent Posts
  Follow Us
If you find these tutorials helpful then please donate. It will lead me to do more tutorials.
Donate