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

Mat*_*ood 3 angular-cli angular angular6

在旧的角度cli中有一个键叫做defaults:

"defaults": {
    "schematics": {
      "collection": "@nrwl/schematics",
      "postGenerate": "npm run format",
      "newProject": [
        "app",
        "lib"
      ]
    },
    "styleExt": "scss",
    "component": {
      "changeDetection": "OnPush"
    }
  }
Run Code Online (Sandbox Code Playgroud)

这家酒店不再存在.如何在角度cli 6+中添加component/changeDetection?还有我可以添加的组件属性列表吗?

小智 10

我不熟悉旧的CLI.这些属性是配置为全局CLI设置还是按项目设置?

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

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


Ren*_*ler 5

通过 Angular CLI,您可以执行以下操作:

ng config schematics.@schematics/angular:component.changeDetection OnPush
Run Code Online (Sandbox Code Playgroud)