如何测试使用Angular CLI ng从其他设备投放的应用? [英] How to test an app created with Angular CLI ng serve from another device?
问题描述
我有一个从头开始使用Angular CLI生成的应用程序. CLI版本angular-cli: 1.0.0-beta.11-webpack.2
I have an app generated with Angular CLI from scratch. CLI version angular-cli: 1.0.0-beta.11-webpack.2
我正在尝试通过智能手机对其进行测试,但我收到连接被拒绝.
I am trying to test it from my smartphone but I get Connection refused.
因此,我在笔记本电脑上运行ng serve
并尝试访问该应用程序:
So, I run ng serve
on my laptop and try to access the app:
- 在笔记本电脑上,使用
localhost
:有效 - 在笔记本电脑上使用IP:连接被拒绝
- 在智能手机上使用IP:连接被拒绝
- From laptop, using
localhost
: Works - From laptop, using IP: Connection refused
- From smartphone, using IP: Connection refused
这曾经与以前的SystemJS版本的CLI一起使用.我检查了是否没有防火墙在运行.
This used to work with the previous, SystemJS version of CLI. I checked that I don't have a firewall running.
如何解决或调试此错误?
How could I fix or debug this error?
我正在使用Mac.
推荐答案
添加值为"0.0.0.0"的主机标志应该可以使您从本地网络上的任何设备访问Web服务器.
Adding the host-flag with value "0.0.0.0" should allow you to access the webserver from any device on your local network.
这应该起作用:
ng serve --host 0.0.0.0
有关说明: https://github.com/angular/angular-cli/pull/1475#issuecomment-235986121
这篇关于如何测试使用Angular CLI ng从其他设备投放的应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!