如何从另一台设备测试使用 Angular CLI ng serve 创建的应用程序? [英] How to test an app created with Angular CLI ng serve from another device?

查看:21
本文介绍了如何从另一台设备测试使用 Angular CLI ng serve 创建的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从头开始使用 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:连接被拒绝

这曾经适用于以前的 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"的主机标志应该允许您从本地网络上的任何设备访问网络服务器.

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 serve 创建的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆