I know from this question and answer on Super User Site running on localhost on desktop is unreachable on android device (PS: this question continues on the question in the link) that the command ng serve
opens a bad configured webserver.
The question is how could I run my site on an Android device without deploying my site. I'll try to run the site on this url http://192.168.0.168:4200
using Angular-CLI.
It lets you use your existing Angular skills, and as a result you get a native UI & performance on iOS and Android.
You can access your host machine with the IP address "10.0. 2.2". This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via "http://10.0.2.2:8080".
Run your angular app by this comand ng serve --public-host (app should run on localhost:4200) You need to do port forwarding, which is thanks to Chrome DevTools realy easy!
After connect your device, run your Angular app serve with ng serve --public-host Now you can access your app in localhost:4200 from mobile device. for Ubuntu people: get the ip address writing this in the terminal: hostname -I and then you can just serve the app with: ng serve --host ip_address
If you want to run your application in mobile browsers without much trouble, then read these articles till the end. Yes, of course, you can use your chrome inspect tools for that which you can find on right-click on chrome browsers and then choose device toggle toolbar.
To do that, you can load your site running on localhost on your mobile devices when they are connected to the same local area network (LAN) such as connecting to the same WiFi. 1. Locate your local IP address Following are how to get your local IP address on Mac OSX and Windows 10.
try ng serve --host
option as explained in this issue: https://github.com/angular/angular-cli/issues/1793 comment by intellix.
ng serve --host 0.0.0.0
<local IP adress>:4200
from any device on the same network.NOTE: If you get CONNECTION_REFUSED just disable your firewall and you should be good to go.
otherwise, try https://ngrok.com/ to open a tunnel from your local network to your computer's localhost. Basically your computer forwards the 4200 port to an external IP and port that any device on the network can access.
First verify your machine IP Address.
ipconfig
in Prompt (copy IPv4).ifconfig |grep inet
in Terminal (copy inet).
In my case this is 192.168.0.10
.
Next, type ng serve --host 192.168.0.10
.
Ok, your app on air for all devices on same network.
Now only http://192.168.0.10:4200/
will work, localhost
not more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With