You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 6无法修改host值?求替代参数方式的修改方案

How to Configure Custom Host in angular.json (Instead of .angular-cli.json)

Absolutely, this is a super common question after Angular CLI switched from .angular-cli.json to angular.json—lots of developers run into this when upgrading projects or setting up new ones!

The good news is you can still set the host directly in the config file, you just need to place it in the right section. Here's a step-by-step breakdown:

  1. Open your root project's angular.json file
  2. Navigate to the projects section, then locate your project name (check the defaultProject field at the top if you're unsure which project to target)
  3. Drill into architect > serve > options
  4. Add a new line with "host": "your-desired-host" — for example, "host": "0.0.0.0" to allow external device access, or a custom local domain like "host": "local.myapp.com"

Here’s a sample of what the updated config will look like:

{
  "projects": {
    "my-angular-project": {
      "architect": {
        "serve": {
          "options": {
            "browserTarget": "my-angular-project:build",
            "port": 4200,
            "host": "0.0.0.0" // Your custom host value here
          },
          "configurations": {
            "production": {
              "browserTarget": "my-angular-project:build:production"
            }
          }
        }
      }
    }
  }
}

If you need environment-specific host settings (like a different host for staging vs production), you can also add the host property inside the corresponding configurations entry:

"configurations": {
  "production": {
    "browserTarget": "my-angular-project:build:production",
    "host": "prod.myapp.com"
  }
}

Save the file, and running ng serve will automatically use your configured host—no more needing to pass it as a command-line argument!

内容的提问来源于stack exchange,提问作者Σωτήρης Ραφαήλ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:51:14