首页 > 解决方案 > Angular ng serve 不在本地主机上托管站点

问题描述

当我ng serve在 CLI 上运行时,我得到以下输出:

Angular Live Development Server 正在监听 localhost:4200,在 http://localhost:4200/ 上打开浏览器

但是当我在浏览器中打开 http://localhost:4200/ 时,什么都没有。

关于如何解决这个问题的任何建议?

这是我的package.json

{
  "name": "eastlaw",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.1.0",
    "@angular/common": "^6.1.0",
    "@angular/compiler": "^6.1.0",
    "@angular/core": "^6.1.0",
    "@angular/forms": "^6.1.0",
    "@angular/http": "^6.1.0",
    "@angular/platform-browser": "^6.1.0",
    "@angular/platform-browser-dynamic": "^6.1.0",
    "@angular/router": "^6.1.0",
    "core-js": "^2.5.4",
    "rxjs": "6.0.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.7.0",
    "@angular/cli": "~6.1.5",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.1.0",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}

标签: htmlcssangularangular-cli

解决方案


要调试问题,请尝试以下操作:

  • ng服务-o
  • 使用键baseURL检查配置文件中提到的默认端口
  • 使用 ng build 命令检查(如果正在生成 webpack)
  • ng 服务 --port 8080 --host 0.0.0.0 --disableHostCheck true

如果可能,请尝试上传浏览器控制台图像


推荐阅读