Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run my Angular site on mobile device that is running localhost on my windows desktop [duplicate]

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.

like image 544
H. Pauwelyn Avatar asked Mar 28 '17 13:03

H. Pauwelyn


People also ask

Can angular app run on mobile?

It lets you use your existing Angular skills, and as a result you get a native UI & performance on iOS and Android.

How do I Preview localhost on a live mobile device?

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

How to run an angular app on localhost?

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!

How to serve an angular app from a mobile device?

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

How to run your application in mobile browsers without any trouble?

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.

How do I load my site on mobile devices?

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.


2 Answers

try ng serve --host option as explained in this issue: https://github.com/angular/angular-cli/issues/1793 comment by intellix.

  1. ng serve --host 0.0.0.0
  2. Find your local IP address by following this
  3. Navigate to <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.

like image 76
Ahmed Musallam Avatar answered Sep 28 '22 06:09

Ahmed Musallam


  1. First verify your machine IP Address.

    • On Windows, type ipconfig in Prompt (copy IPv4).
    • On Mac, type ifconfig |grep inet in Terminal (copy inet).


    In my case this is 192.168.0.10.

  2. Next, type ng serve --host 192.168.0.10.

  3. Ok, your app on air for all devices on same network.

  4. Now only http://192.168.0.10:4200/ will work, localhost not more.

like image 37
Shabbir Dhangot Avatar answered Sep 28 '22 06:09

Shabbir Dhangot