【问题标题】:How to run angular 2 application by angular cli如何通过 Angular cli 运行 Angular 2 应用程序
【发布时间】:2018-09-21 18:52:46
【问题描述】:

我正在尝试使用 Angular 2 创建一个应用程序。我从 github 获得了一个示例项目文件夹。当我运行该应用程序时,我收到“找不到本地工作区文件 ('angular.json')”错误消息。如何解决这个问题?

包.json

{
"name": "demo-app",
"version": "1.0.0",
"author": "Aravind",
"description": "set up files for the first Demo App",
"scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lint": "tslint ./app/**/*.ts -t verbose",
    "lite": "lite-server",
    "typings": "typings",
    "postinstall": "typings install"
},
"license": "ISC",
"dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/router": "3.0.0",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.27",
    "zone.js": "^0.6.23",
    "bootstrap": "^3.3.6"
},
"devDependencies": {
    "concurrently": "^2.2.0",
    "lite-server": "^2.2.0",
    "tslint": "^3.7.4",
    "typescript": "^2.0.2",
    "typings": "^1.0.4"
},
"repository": {}
 }

【问题讨论】:

  • 使用 ng serve 命令运行
  • 我们现在是 2018 年,启动 Angular 2 应用程序很奇怪,因为 Angular 6 已经发布了 :)。您分叉的项目似乎已过时:)

标签: angular angular2-forms


【解决方案1】:

看起来您的 Angular CLI 是 v6+,而您的 Angular 应用程序是 v2。您的项目中必须有angular-cli.json 文件。在最新版本的 CLI 中,在 v6 之后,config.文件被重命名为angular.json,并稍作改动。如果是这种情况,请创建angular.json 文件并进行相应更新。

否则,只需使用ng new <appName> 创建一个新项目并点击ng serve。由于 Angular CLI 是您机器上最新安装的,所以它会默认创建 angular.json

详细了解 Angular CLI 命令here

【讨论】:

    【解决方案2】:

    是的,您的 Angular 项目看起来已经过时了,最新的 Angular 使用 angular.json,而不是 angular-cli.json

    要么要求创建者更新它,要么按照以下步骤自行更新:https://update.angular.io/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多