`ng new --view-encapsulation` has no effect on generated components
維護者通常 1 天內回覆
已經有一個關聯 PR 被合併了。
- #34389 來自 @MeAkib —— 已合併
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- angular, typescript
- 領域
- build-system, cli
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- TypeScript
- 星號
- 27k
- 分支
- 11.8k
- 平均合併
- 1 天 6 小時
- 30 天內合併 PR
- 216
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
angular/angular-cli 的其他 Issue
-
area: @angular/build gemini-triaged
難度 2/5 1-3 小時 新手友好度 74/100
angular/angular-cli#33955 ·
維護者通常 1 天內回覆
-
area: @angular/cli gemini-triaged
難度 2/5 1-3 小時 新手友好度 72/100
angular/angular-cli#33055 · 1 則留言 · 3 個 reaction ·
維護者通常 1 天內回覆
-
@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-111771可能已有人在做 @florimond-collette 今天認領。 未關閉area: @angular/cli
難度 2/5 1-3 小時 新手友好度 35/100
angular/angular-cli#34455 ·
維護者通常 1 天內回覆
-
@angular/build 22.2.x, 21.2.x and 20.3.x depend on [email protected] / [email protected] which are vulnerable to CVE-2026-112943可能已有人在做 @florimond-collette 今天認領。 未關閉area: @angular/build
難度 3/5 1-2 天 新手友好度 25/100
angular/angular-cli#34452 ·
維護者通常 1 天內回覆
-
`ng generate app-shell` and `ng generate module --route` produce broken imports when a component `type` is configured可能已有人在做 @MeAkib 今天認領。 未關閉area: @schematics/angular
難度 3/5 1-2 天 新手友好度 35/100
angular/angular-cli#34449 ·
維護者通常 1 天內回覆
查看 angular/angular-cli 的全部 Issue
相似的 Issue
-
check:passed streams:edit
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
area:mcp bug has repro platform:vscode regression
難度 2/5 1-3 小時 新手友好度 68/100
anthropics/claude-code#103970 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆
-
sdk-typescript: unquoted COPY globs in shell form are silently dropped from the image build context未關閉bug javascript
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆