Angular 6 在 "e2e/app"文件夹中生成服务

标签 angular angular6

我最近将我的 Angular 4 升级到了 6。 现在我尝试下面的命令

ng generate service security/security

但它在文件夹“e2e/app”下而不是在“src/app”下创建了服务 下面是我的 angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "xyz": {
      "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": [
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              "src/style.scss",
              "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"
                }
              ]
            },
            "test": {
              "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.test.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "xyz:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "xyz:build:production"
            },
            "test": {
              "browserTarget": "xyz:build:test"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "xyz: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": [
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/tether/dist/js/tether.min.js",
              "node_modules/bootstrap/dist/js/bootstrap.min.js"
            ],
            "styles": [
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              "src/style.scss",
              "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": []
          }
        }
      }
    },
    "xyz-e2e": {
      "root": "",
      "sourceRoot": "e2e",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "xyz:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": []
          }
        }
      }
    }
  },
  "defaultProject": "xyz",
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "styleext": "css"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  }
}

我最近从 angular 4 升级到 6 当我尝试使用 angular-cli ne new my-app 命令创建的新应用程序时 它在 src/app 文件夹中正确创建

最佳答案

angular.json 文件中,搜索:my-project-e2e

my-project 替换为您的项目名称。

更改:

  "root": "" to  "root": "e2e"

我在这里找到它并且对我有用。

Angular CLI 6 Component Generate Issue Solution

关于Angular 6 在 "e2e/app"文件夹中生成服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51061415/

相关文章:

angular - 根据用户选择顺序保存多个选择的 ngModel 绑定(bind)值

angular - HttpClient 返回 "Cannot read property ' get' of Undefined[Angular 7]

css - 在 Angular 中为 Less 使用全局变量

angular6 - 无法解析 'rxjs/add/operator/do'

javascript - 如何使用 Angular2 将 html 代码附加到 div 元素

angular - 从 6 到 7 的 Angular 迁移后无法比较 Jasmine 中的枚举

Angular CLI 6 - 使用 Source Maps 构建 Angular 库

抛出异常后 Angular 2 不更新 View

javascript - 如何在 Angular 中获取所选选项的索引

Angular:如何确定带参数的事件路线?