现有项目的角度问题

时间:2017-07-09 13:44:47

标签: node.js angular

我在Windows 7上。

我导入了一个由朋友启动的Angular项目,但是在安装node和angular之后我遇到了一些问题,我能够使用这个命令运行项目:

C:\NG\projectName>npm start

但是当我尝试使用此命令生成新组件时,我收到错误:

C:\NG\projectName\app\components>ng g c myNewComponentName
installing component
Unable to find any apps in `.angular-cli.json`

angular-cli.json文件位于:C:\ NG \ projectName \ node_modules \ @angular \ cli \ blueprints \ ng \ files \并包含以下代码:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "<%= htmlComponentName %>"
  },
  "apps": [
    {
      "root": "<%= sourceDir %>",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "<%= prefix %>",
      "styles": [
        "styles.<%= styleExt %>"
      ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "<%= sourceDir %>/tsconfig.app.json"
    },
    {
      "project": "<%= sourceDir %>/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "<%= styleExt %>",<% if (!minimal) { %>
    "component": {}<% } else { %>
    "component": {
      "spec": false,
      "inlineStyle": true,
      "inlineTemplate": true
    },
    "directive": {
      "spec": false
    },
    "class": {
      "spec": false
    },
    "guard": {
      "spec": false
    },
    "module": {
      "spec": false
    },
    "pipe": {
      "spec": false
    },
    "service": {
      "spec": false
    } <% } %>
  }
}

我该如何解决?

有关信息:

C:\NG\projectName\app\components>ng -v
@angular/cli: 1.2.0
node: 6.11.0
os: win32 x64
@angular/animations: 4.2.5
@angular/common: 4.2.5
@angular/compiler: 4.2.5
@angular/compiler-cli: 4.2.5
@angular/core: 4.2.5
@angular/forms: 4.2.5
@angular/http: 4.2.5
@angular/platform-browser: 4.2.5
@angular/platform-browser-dynamic: 4.2.5
@angular/platform-server: error
@angular/router: 4.2.5
@angular/tsc-wrapped: 4.0.3
@angular/upgrade: error
@angular/cli: 1.2.0

C:\NG\projectName\app\components>npm -v
3.10.10

谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

问题很可能是项目未使用角度cli初始化。

ng init中运行 C:\NG\projectName> 可以解决问题¹