简体   繁体   English

Angular(7)扩展原理图

[英]Angular(7) extending schematics

I have several components for wich i wrote some schematics for installing that components. 我有几个组件,我写了一些安装组件的原理图。 For maintainablility my schematics are in a separate package. 为了保持可维护性,我的原理图在一个单独的包中。

After merging my schematics from Angular6 to Angular7 my schematics cannot be found. 在将我的原理图从Angular6合并到Angular7后,我的原理图无法找到。

So in my "package.json" of my component: 所以在我的组件的“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", } 

In "./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" } } } 

The "collections.json" of @my-project/schematics: @ 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" } } } 

So when executing "ng add @my-project/my-component" i get the message: 'Schematic "my-component-install" not found in collection "@my-project/my-comonent".' 因此,当执行“ng add @ my-project / my-component”时,我收到消息:'Schematic'my-component-install“找不到集合”@ my-project / my-comonent“。' However in Angular6 this worked. 但是在Angular6中这很有效。

Can anyone tell me how to fix this? 谁能告诉我如何解决这个问题?

I am a little confused with your structure, but I'll give my best shot — So if you have a schematics, let's say 'my-schematics' and it has 'ng-add' as a schematic. 我对你的结构有点困惑,但是我会尽我所能 - 所以如果你有一个原理图,让我们说'my-schematics'并且它有'ng-add'作为原理图。 'my-schematics' extends angular schematics, so it can do whatever angular schematics can do, but with additional logic. 'my-schematics'扩展了角度原理图,因此它可以做任何角度原理图可以做的事情,但有额外的逻辑。 This is what the collection.json of 'my-schematics' would look like - 这就是'my-schematics'的collection.json看起来像 -

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

Now in your project you can call my-schematics:ng-add (and also my-schematics:component or any other angular schematic function) 现在在您的项目中,您可以调用my-schematics:ng-add(以及my-schematics:组件或任何其他角度逻辑示意图函数)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM