`ng new --view-encapsulation` has no effect on generated components
Les mainteneurs répondent en général sous 1 jour
Une pull request liée a déjà été fusionnée.
- #34389 par @MeAkib — fusionnée
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- angular, typescript
- Domaine
- build-system, cli
Piste de recherche
The issue identifies the ng new and ng generate application paths, the generated root App component, angular.json component schematic defaults, and main.ts bootstrap options. Trace how --view-encapsulation flows through those generation paths and compare the generated files with the reproduction steps. Done means the selected mode affects the initial component and later generated components under AOT.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Command
new
Is this a regression?
- 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
Appcomponent is generated withoutencapsulation, so its styles stay scoped (Emulated). - The value is not saved to the project's
@schematics/angular:componentdefaults inangular.json, so components
generated later withng g calso use Emulated. - For
--no-standaloneapps,main.tsgetsbootstrapModule(AppModule, { defaultEncapsulation: ViewEncapsulation.X }).
defaultEncapsulationis only read by the JIT compiler, so it has no effect with AOT, which is the default for
ng buildandng serve.
This looks like #13689 again: it was fixed in 89797900db by setting the encapsulation on the root component and in
bootstrapModule, but the root component part was removed in 58bc5b8f2a (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; }tosrc/app/app.css ng build --configuration development- The output contains
h1[_ngcontent-%COMP%], i.e. the styles are still encapsulated. angular.jsonhas noviewEncapsulationunderprojects.ve-repro.schematics, song g c fooalso 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.
- Langage dominant
- TypeScript
- Étoiles
- 27k
- Forks
- 11.8k
- Merge moyen
- 1 j 6 h
- PR mergées (30 j)
- 216
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de angular/angular-cli
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-serverOuvertearea: @angular/build gemini-triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
angular/angular-cli#33955 ·
Les mainteneurs répondent en général sous 1 jour
-
area: @angular/cli gemini-triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
angular/angular-cli#33055 · 1 commentaire · 3 réactions ·
Les mainteneurs répondent en général sous 1 jour
-
@angular/cli 21.2.x and 20.3.x depend on @modelcontextprotocol/[email protected] which is vulnerable to CVE-2026-111767, CVE-2026-111768, CVE-2026-111769 and CVE-2026-111771Peut-être pris @florimond-collette l’a pris il y a 1 jour. Ouvertearea: @angular/cli
Difficulté 2/5 1-3 heures Accessibilité débutants 35/100
angular/angular-cli#34455 ·
Les mainteneurs répondent en général sous 1 jour
-
@angular/build 22.2.x, 21.2.x and 20.3.x depend on [email protected] / [email protected] which are vulnerable to CVE-2026-112943Peut-être pris @florimond-collette l’a pris il y a 1 jour. Ouvertearea: @angular/build
Difficulté 3/5 1-2 jours Accessibilité débutants 25/100
angular/angular-cli#34452 ·
Les mainteneurs répondent en général sous 1 jour
-
`ng generate app-shell` and `ng generate module --route` produce broken imports when a component `type` is configuredPeut-être pris @MeAkib l’a pris il y a 1 jour. Ouvertearea: @schematics/angular
Difficulté 3/5 1-2 jours Accessibilité débutants 35/100
angular/angular-cli#34449 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de angular/angular-cli
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
paperclipai/paperclip#17151 ·
Les mainteneurs répondent en général sous 1 jour
-
needs-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
AgoraIO-Extensions/agent-infra#3159 ·
Les mainteneurs répondent en général sous 1 jour
-
blocklist addition
Difficulté 1/5 Moins d'une heure Accessibilité débutants 66/100
MetaMask/eth-phishing-detect#304596 ·
Les mainteneurs répondent en général sous 1 jour
-
friction
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
kentcdodds/kody#4142 ·
-
[Bug] Statistics | Task statistics are always empty on MikroORM with MySQL or SQLitePeut-être pris @NdekoCode l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
ever-co/ever-gauzy#11214 ·
Les mainteneurs répondent en général sous 1 jour