Angular – Get the ip address of the user

In this short blog post, I will show you how to get the ip address of the user.

I’m using v5 for this tutorial. If you are using v2/v4, just replace the HttpClient with just Http.

Here it goes:

This should work now. Though the code editor is telling me that this line

this.ipAddress = data.ip;

is wrong.

Looking at the official docs for the http client, I need to tell the httpclient what the type response will be so  I will create an interface with just a ip property of string.

And add it like this

That’s it.

Thanks for reading.

Here’s the stackblitz demo