【问题标题】:Executing "ng serve" or "npm start" command browser is not opening automatically执行“ng serve”或“npm start”命令浏览器不会自动打开
【发布时间】:2017-03-22 05:44:35
【问题描述】:

我已经按照安装部分中给出的步骤使用 angular-cli 生成了一个项目。项目现在正在运行。但我必须通过在浏览器中输入http://localhost:4200/ 来手动打开浏览器。

有没有可能当用户执行“ng serve”或“npm start”命令时,浏览器会自动打开?

请让我知道是否可行或为此提供任何解决方案。

【问题讨论】:

  • 在 angular/cli 中使用 --open(或仅 -o)选项将自动在 localhost:4200/.For 上打开浏览器,例如 ng serve --open

标签: angular npm


【解决方案1】:

根据the documentation,您可以使用带有ng serve 的标志:

--open (-o) 在默认浏览器中打开网址。

您可能需要针对此功能更新您的版本,因为 wiki 页面的修订历史表明它是最近添加的。

【讨论】:

  • @ChanakaJ 在您使用时检查ng -v 告诉您的内容
  • _ _ ____ _ ___ / \ _ __ __ _ | | __ _ _ __ / _| | | | / △ \ | ' \ / ` | | | | |/ _` | '_| | | | | | | / ___ \| | | | (| | |_| | | (_| | | | |___| | | | /_/ __| |_|_, |_, |_|_,_|_| ____|_____|___| |___/ @angular/cli: 1.0.0-rc.4 节点: 6.10.0 操作系统: win32 x64
  • @ChanakaJ ascii 艺术不谈,这似乎足以支持国旗。是吗?
【解决方案2】:

angular-cli 团队的一位开发者在 2016 年 6 月 17 日说;

我们目前没有这个功能,没有。但我会离开 问题以“很高兴”的形式公开。

但是

您可以更改 npm start 在 package.json 中的作用。

例如改变

"start": "ng serve"

"start": "start http://localhost:4201 & ng serve -port 4201"

【讨论】:

  • 在某些项目中没有 npm start open browser automatically
  • 你能链接到他们说的地方吗?从上面的评论看来,它不再是真的了。
  • 现在你需要 ============= npm start ============ 来运行 app,而不是 ng serve 。只是说
猜你喜欢
  • 2017-03-19
  • 1970-01-01
  • 2017-07-07
  • 1970-01-01
  • 2017-06-07
  • 2021-01-13
  • 2022-12-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多