我的手机和电脑都在同一个wifi上。当我运行ng serve时,我会用我的电脑在Chrome中打开localhost:4200,它可以正常工作。
但是我用我的手机打开192.168.1.107:4200,它不能工作。
当我使用create-react-app时。它起作用了。
绿色是棱角。白色是react

发布于 2017-11-26 17:29:21
为了使您的服务器在本地网络中可用,您需要使用以下命令:
ng serve --host 192.168.1.107然后,该应用程序将在您网络中的每台设备上的192.168.1.107:4200上可用。
如果您不知道您的局域网地址是什么,您可以在基于unix的操作系统上执行ifconfig | grep broadcast -第一个IP是您的计算机,或者在Windows机上执行ipconfig。
发布于 2019-11-06 03:27:49
Chrome Chrome通过本教程设置您的手机Chrome Remote debugging
localhost:4200)
- Tutorial -> [Chrome Access Local Servers](https://developers.google.com/web/tools/chrome-devtools/remote-debugging/local-server)
- You need only to forward one port, you do it by clicking `Add rule` button which is located in `Remote devices` tab in the `settings` (see [Tutorial](https://developers.google.com/web/tools/chrome-devtools/remote-debugging/local-server)), then into `Device port` you write `4200` and into `Local address` you enter `localhost:4200`
- In my scenario I also needed to forward other port, because I was running my backend server on localhost too, my backend is running on `localhost:5010`, so I simply add new rule like i said above `Device Port: 5010` and `Local address: localhost:5010`
localhost:4200,它应该会显示您的应用程序- The best part is that you can open the DevTools for the tab you have opened in your phone from the desktop DevTools and easily debug your page on phone from the Desktop (inspect the elements, see console, etc...) Your page will also be reloaded after change is made in the code...
发布于 2019-10-14 09:19:09
我不确定这个命令在Angular 8中是否改变了,但这些都不适用于我。
我所要做的就是手动指定端口,瞧!
ng s --host 0.0.0.0 --port 4200(请注意,您也可以使用您的实际IP地址来代替0.0.0.0;这两种方法对我都有效。)
https://stackoverflow.com/questions/47493325
复制相似问题