You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ng new --view-encapsulation has no effect on generated components #34388
Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
The --view-encapsulation option of ng new / ng generate application is documented as "Sets the view
encapsulation mode for components in the initial project", but it currently has no effect:
The root App component is generated without encapsulation, so its styles stay scoped (Emulated).
The value is not saved to the project's @schematics/angular:component defaults in angular.json, so components
generated later with ng g c also use Emulated.
For --no-standalone apps, main.ts gets bootstrapModule(AppModule, { defaultEncapsulation: ViewEncapsulation.X }). defaultEncapsulation is only read by the JIT compiler, so it has no effect with AOT, which is the default for ng build and ng serve.
This looks like #13689 again: it was fixed in 8979790 by setting the encapsulation on the root component and in bootstrapModule, but the root component part was removed in 58bc5b8 (for #13742, invalid generated code), leaving
only the JIT-only option.
Minimal Reproduction
ng new ve-repro --defaults --view-encapsulation=None (same result with --no-standalone)
Add h1 { color: red; } to src/app/app.css
ng build --configuration development
The output contains h1[_ngcontent-%COMP%], i.e. the styles are still encapsulated.
angular.json has no viewEncapsulation under projects.ve-repro.schematics, so ng g c foo also generates an
Emulated component.
Exception or Error
Your Environment
Latest
Anything else relevant?
Possible fix: set encapsulation on the generated root component, save viewEncapsulation in the component schematic
defaults, and drop defaultEncapsulation from main.ts. Happy to send a PR.
Activity
fix(@schematics/angular): apply `viewEncapsulation` to generated appl…
fix(@schematics/angular): apply `viewEncapsulation` to generated appl…
fix(@schematics/angular): apply `viewEncapsulation` to generated appl…