how to get public IP in Angular Project? Is there any method or URL for getting public IP from the client-side.
Below, I listed the code was I used. but I can't subscribe to that response.
this.httpService.get<{ ip: string }>
("http://icanhazip.com/").subscribe(data => {
console.log(data)
});
In fact, there is no way of getting the user's IP without doing a roundtrip to a server. This is because the Angular project runs completely in the browser and could even run there without any internet connection. Only the server can determine the IP address. The solution is to call a server that then returns the public IP. You can either use an existing service (as mentioned above or here: https://stackoverflow.com/a/35123097/9032927) or build your own simple server script, e.g. with PHP:
{ "ip": "<?php echo $_SERVER['REMOTE_ADDR']; ?>" }
tl;dr: You need a server for this that returns the IP address on request.