Skip to content

Add ability to configure default changeDetection and viewEncapsulation used by component generator #2822

@jschwarty

Description

@jschwarty

Overview of the Requested Feature

Would like to have a way to set the global behavior of the component generator to handle writing the following component metadata properties:

  • changeDetection
  • viewEncapsulation

Something like the ability to set the default values to use for these from within the angular-cli.json file (or maybe some other generators config file) like so:

{

  . . .

  "defaults": {
    "changeDetection": "OnPush",
    "viewEncapsulation": "Native",
    . . .
  }
}

with the following potential string values:

  • "OnPush" or "Default" for changeDetection
  • "Emulated", "Native" or "None" for viewEncapsulation

If these properties are not in the angular-cli.json file then the metadata properties would not be included in the component generator template (same behavior it currently does).

Change Detection

If `"changeDetection" is set, the component metadata property would be included and set in the component generator template like so:

@Component({
  . . .
 changeDetection: ChangeDetectionStrategy.OnPush,
  . . .
})

with "OnPush" using ChangeDetectionStrategy.OnPush and "Default" using ChangeDetectionStrategy.Default.

View Encapsulation

If `"viewEncapsulation" is set, the component metadata property would be included and set in the component generator template like so:

@Component({
  . . .
 viewEncapsulation: ViewEncapsulation.Native,
  . . .
})

with "Native" using ViewEncapsulation.Native, "Emulated" using ViewEncapsulation.Emulated and "None" using ViewEncapsulation.None.

Note

I think the ideal solution would be to have a way to create custom generator templates at a project level so users could control more than just the component metadata, but I am not sure if that is on the radar and if so, how far out it is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions