如何在 angular cli 6+ 中添加组件默认值

How do I add component defaults in angular cli 6+

在旧的 angular cli 中有一个名为 defaults 的密钥:

"defaults": {
    "schematics": {
      "collection": "@nrwl/schematics",
      "postGenerate": "npm run format",
      "newProject": [
        "app",
        "lib"
      ]
    },
    "styleExt": "scss",
    "component": {
      "changeDetection": "OnPush"
    }
  }

此 属性 已不存在。如何在推送 angular cli 6+ 时添加 component/changeDetection?此外,是否有我可以添加的组件属性列表?

可以在 angular.json 的原理图部分查看原理图:https://github.com/angular/angular-cli/wiki/angular-workspace I'm not sure if you can directly edit the default schematics for component, or you have to create your own schematic that uses the component schematic, as you see in this tutorial: https://blog.angular.io/schematics-an-introduction-dc1dfbc2a2b2(部分:调用另一个原理图)。

我不太熟悉旧的 CLI。这些属性是配置为全局 CLI 设置还是每个项目的设置?

在新的 Angular CLI 中,您可以通过将 schematics 对象更新为以下内容来复制 angular.json 文件中的每个项目设置:

"projects": { "my-project": { "root": "", "sourceRoot": "src", "projectType": "application", "prefix": "app", "schematics": { "@schematics/angular:component": { "changeDetection": "OnPush" } },

通过 Angular CLI,您可以按如下方式进行操作:

ng config schematics.@schematics/angular:component.changeDetection OnPush