“连接被拒绝” Angular 4 localhost开发

时间:2018-07-26 06:00:14

标签: node.js angular mean-stack

在本地运行Angular 4应用程序时出现“拒绝连接”页面。

URL为http://localhost:4200/

使用ng serve --open命令运行应用。

更新1:angular.json

我发现某些角度的cli文件现在更改为 angular.json

bellow是agnular.json

中的详细信息
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
  "angular-forms": {
    "root": "",
    "sourceRoot": "src",
    "projectType": "application",
    "architect": {
      "build": {
        "builder": "@angular-devkit/build-angular:browser",
        "options": {
          "outputPath": "dist",
          "index": "src/index.html",
          "main": "src/main.ts",
          "tsConfig": "src/tsconfig.app.json",
          "polyfills": "src/polyfills.ts",
          "assets": [
            "src/assets",
            "src/favicon.ico"
          ],
          "styles": [
            "src/styles.css"
          ],
          "scripts": []
        },
        "configurations": {
          "production": {
            "optimization": true,
            "outputHashing": "all",
            "sourceMap": false,
            "extractCss": true,
            "namedChunks": false,
            "aot": true,
            "extractLicenses": true,
            "vendorChunk": false,
            "buildOptimizer": true,
            "fileReplacements": [
              {
                "replace": "src/environments/environment.ts",
                "with": "src/environments/environment.prod.ts"
              }
          ]
        }
      }
    },
    "serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "angular-forms:build"
      },
      "configurations": {
        "production": {
          "browserTarget": "angular-forms:build:production"
        }
      }
    },
    "extract-i18n": {
      "builder": "@angular-devkit/build-angular:extract-i18n",
      "options": {
        "browserTarget": "angular-forms:build"
      }
    },
    "test": {
      "builder": "@angular-devkit/build-angular:karma",
      "options": {
        "main": "src/test.ts",
        "karmaConfig": "./karma.conf.js",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.spec.json",
        "scripts": [],
        "styles": [
          "src/styles.css"
        ],
        "assets": [
          "src/assets",
          "src/favicon.ico"
        ]
      }
    },
    "lint": {
      "builder": "@angular-devkit/build-angular:tslint",
      "options": {
        "tsConfig": [
          "src/tsconfig.app.json",
          "src/tsconfig.spec.json"
        ],
        "exclude": [
          "**/node_modules/**"
        ]
      }
    }
  }
},
"angular-forms-e2e": {
  "root": "",
  "sourceRoot": "",
  "projectType": "application",
  "architect": {
    "e2e": {
      "builder": "@angular-devkit/build-angular:protractor",
      "options": {
        "protractorConfig": "./protractor.conf.js",
        "devServerTarget": "angular-forms:serve"
      }
    },
    "lint": {
      "builder": "@angular-devkit/build-angular:tslint",
      "options": {
        "tsConfig": [
          "e2e/tsconfig.e2e.json"
        ],
        "exclude": [
          "**/node_modules/**"
        ]
      }
    }
  }
}
},
"defaultProject": "angular-forms",
"schematics": {
"@schematics/angular:component": {
  "prefix": "app",
  "styleext": "css"
},
"@schematics/angular:directive": {
  "prefix": "app"
}
}
}

如果需要更多详细信息,请告诉我

附加了屏幕截图,以获取更多详细信息。

enter image description here

3 个答案:

答案 0 :(得分:1)

转到命令行并运行ng serve --port 4200

希望这会有所帮助。

答案 1 :(得分:0)

尝试使用localhost这样访问您的应用,而不是IP

(假设您使用的是Windows)在命令行中,键入=> ipconfig ,然后复制它返回的IP地址,

例如,如果IP地址为192.168.0.10,则您可以按以下方式访问您的应用程序(发出ng server后),

http://192.168.0.10:4200

希望这会有所帮助!

答案 2 :(得分:0)

我已经找到了解决方案,这很简单。当@Devid向mi询问有关公司代理的问题时,我已经开始朝这个方向搜索解决方案。最终,我发现我的LAN代理设置中存在小错误。

在配置代理服务器时,我忘记启用选项“为本地地址绕过代理服务器”,这会导致mi出现以上错误。

下面是屏幕快照,以获取更多详细信息。

enter image description here