Angular(7) 扩展原理图

标签 angular angular-schematics angular7

我有几个组件,我为此编写了一些原理图来安装这些组件。为了便于维护,我的原理图位于单独的包中。

将我的原理图从 Angular6 合并到 Angular7 后,找不到我的原理图。

所以在我组件的“package.json”中:

    {
      "name": "@my-project/my-component",
      "version": "4.0.0",
      "dependencies": {
        "@my-project/schematics": "^2.0.0",
        "tslib": "^1.9.0"
      },
      "peerDependencies": {
        "@angular/common": "^7.0.0",
        "@angular/core": "^7.0.0"
      },
      "schematics": "./schematics/collection.json",
    }

在“./schematics/collection.json”中:

    {
      "$schema": "./node_modules/@angular-devkit/schematics/collection-schema.json",
      "schematics": {
        "ng-add": {
          "extends" : "@my-project/schematics:my-component-install"
        }
      }
    }

@my-project/schematics 的“collections.json”:

    {
      "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
      "schematics": {
          "my-component-install": {
          "description": "Schematics for installation of @my-project/my-component",
          "schema": "./my-component/install/schema.json",
          "factory": "./my-component/install/index"
        }
      }
    }

所以当执行“ng add @my-project/my-component”时我得到消息:

'Schematic "my-component-install" not found in collection "@my-project/my-comonent".'

但是在 Angular6 中这有效。

谁能告诉我如何解决这个问题?

最佳答案

我对你的结构有点困惑,但我会尽力而为 — 所以如果你有原理图,假设是“my-schematics”,它有“ng-add”作为原理图。 “我的原理图”扩展了 Angular 原理图,因此它可以做任何 Angular 原理图可以做的事情,但有额外的逻辑。 这就是“my-schematics”的 collection.json 的样子 -

{
    “$schema”:.....
    “extends”: [
        “@schematics/angular”
    ],
    “schematics”: {
        “ng-add”: { 
            “description”:.., “factory”:..., “schema”:...
         }
     }
}

现在在你的项目中你可以调用 my-schematics:ng-add (还有 my-schematics:component 或任何其他 Angular 原理图函数)

关于Angular(7) 扩展原理图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52945697/

相关文章:

angular - Microsoft 使用 Angular 登录

css - Angular:css 变量在组件中不可用

angular - 在 angular-cli 中打印自定义原理图日志

angular-cli - 角度示意图 : Error when running unit test in library

Angular 7 无法包含自定义 typescript 定义文件

html - Bootstrap : Select Tag Cutting off texts below

angular - Angular/NativeScript 应用程序中的单元测试

angular - Office.js : Increasingly poorer performance writing a large amount of rows to Excel

Angular2 将动态样式应用于范围控制更改事件

Angular 示意图 : Not found : my-schematic error