Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add component defaults in angular cli 6+

In the old angular cli there was a key called defaults:

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

This property no longer exsists. How do I add component/changeDetection on push in angular cli 6+? moreover is there a list of component properties I can add?

like image 444
Armeen Harwood Avatar asked Jun 01 '18 23:06

Armeen Harwood


People also ask

What is the command to create a component in Angular 6?

Creating a component using the Angular CLIlink Run the ng generate component <component-name> command, where <component-name> is the name of your new component.

What is component TS file in Angular?

component. spec. ts: This file is a unit testing file related to app component. This file is used along with other unit tests. It is run from Angular CLI by the command ng test.


2 Answers

I'm not as familiar with the old CLI. Were those properties configured as global CLI settings, or a per-project setting?

In the new Angular CLI, you can replicate per-project settings in the angular.json file by updating the schematics object to the following:

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

like image 154
ericksoen Avatar answered Oct 25 '22 18:10

ericksoen


Via the Angular CLI, you can do it as follows:

ng config schematics.@schematics/angular:component.changeDetection OnPush
like image 40
René Winkler Avatar answered Oct 25 '22 18:10

René Winkler