Title: ng-content and ViewEncapsulation.Emulated prevents styling in Child Component · Issue #12639 · angular/angular · GitHub
Open Graph Title: ng-content and ViewEncapsulation.Emulated prevents styling in Child Component · Issue #12639 · angular/angular
X Title: ng-content and ViewEncapsulation.Emulated prevents styling in Child Component · Issue #12639 · angular/angular
Description: I'm submitting a ... (check one with "x") [X] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/an...
Open Graph Description: I'm submitting a ... (check one with "x") [X] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request...
X Description: I'm submitting a ... (check one with "x") [X] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not su...
Opengraph URL: https://github.com/angular/angular/issues/12639
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ng-content and ViewEncapsulation.Emulated prevents styling in Child Component","articleBody":"\u003c!--\r\nIF YOU DON'T FILL OUT THE FOLLOWING INFORMATION WE MIGHT CLOSE YOUR ISSUE WITHOUT INVESTIGATING\r\n-->\r\n\r\n**I'm submitting a ...** (check one with \"x\")\r\n```\r\n[X] bug report => search github for a similar issue or PR before submitting\r\n[ ] feature request\r\n[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n```\r\n\r\n**Current behavior**\r\n\u003c!-- Describe how the bug manifests. -->\r\n\r\nWhen using `ng-content` in a Component and `ViewEncapsulation.Emulated` the elements that are transcluded in the ng-content can not be styled in the Component .css file. This can be reproduced with JIT and AOT. \r\n\r\nFor instance, I have the following button component that is used like so in a template:\r\n\r\n```\r\n \u003cui-button >\r\n \u003cspan> Connect \u003c/span>\r\n \u003c/ui-button>\r\n```\r\n\r\nui-button.component.html:\r\n\r\n```\r\n\u003cdiv class=\"button\">\r\n \u003cng-content>\u003c/ng-content>\r\n\u003c/div>\r\n\r\n```\r\n\r\nui-button.component.css:\r\n\r\n```\r\n:host {\r\n display: inline-block;\r\n min-width: 80px;\r\n max-width: 180px;\r\n}\r\n.button span {\r\n float: right;\r\n}\r\n```\r\n\r\nThe `\u003cspan>` will not be styled `float:right`.\r\n\r\nThe element is compiled like this in the DOM:\r\n\r\n```\r\n\u003cui-button _ngcontent-uid-4 class=\"ui__remote\" _nghost-uid-5>\r\n \u003cdiv _ngcontent-uid-5 class=\"button\">\r\n \u003cspan _ngcontent-uid-4> Connect \u003c/span>\r\n \u003c/div>\r\n\u003c/ui-button>\r\n```\r\n\r\nWhen inspecting the compiled `\u003cstyle>` a declaration is found for the `.button`:\r\n\r\n```\r\n.button[_ngcontent-uid-5] {\r\n\r\n}\r\n```\r\n\r\nand furthermore a declaration for the `span`:\r\n\r\n```\r\n.button[_ngcontent-uid-5] span[_ngcontent-uid-5] {\r\n float: right;\r\n padding-right: 8px;\r\n padding-top: 6px;\r\n}\r\n```\r\n\r\nBut the compiled `span` has the id of the parent Component, so it cannot be styled in the child Component. \r\n\r\n\r\n\r\n**Expected behavior**\r\n\u003c!-- Describe what the behavior would be without the bug. -->\r\n\r\nWhen a template is transcluded with `ng-content` it is expected that the elements are classed so they can be styled within the context of the child Component.\r\n\r\n**Minimal reproduction of the problem with instructions**\r\n\u003c!--\r\nIf the current behavior is a bug or you can illustrate your feature request better with an example, \r\nplease provide the *STEPS TO REPRODUCE* and if possible a *MINIMAL DEMO* of the problem via\r\nhttps://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).\r\n-->\r\n\r\n**What is the motivation / use case for changing the behavior?**\r\n\u003c!-- Describe the motivation or the concrete use case -->\r\n\r\nIf this were Native Shadow DOM, the styling would work, the emulation should provide as close an API as possible to the Native implementation.\r\n\r\n**Please tell us about your environment:**\r\n\u003c!-- Operating system, IDE, package manager, HTTP server, ... -->\r\n\r\nMacOS, Atom, npm, live-server\r\n\r\n* **Angular version:** 2.0.X\r\n\u003c!-- Check whether this is still an issue in the most recent Angular version -->\r\n\r\n2.1.2\r\n\r\n* **Browser:** [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]\r\n\u003c!-- All browsers where this could be reproduced -->\r\n\r\nAll browsers\r\n \r\n* **Language:** [all | TypeScript X.X | ES6/7 | ES5]\r\n\r\nTS 2.0.3\r\n\r\n* **Node (for AoT issues):** `node --version` = \r\n","author":{"url":"https://github.com/steveblue","@type":"Person","name":"steveblue"},"datePublished":"2016-11-01T06:36:23Z","url":"https://github.com/angular/angular/issues/12639"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4e61fd8e-6ad6-8356-7499-2efd34dbe9b3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B6DC:27E5CD:2778261:327C4A1:6B018CF8 |
| html-safe-nonce | 577955e5c24c69d5195652c94d84af47838938fadb423c337d6a2e7e4fa70fec |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNkRDOjI3RTVDRDoyNzc4MjYxOjMyN0M0QTE6NkIwMThDRjgiLCJ2aXNpdG9yX2lkIjoiMzc1ODQzNzA0MTEyNjM0NTk3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 442159345bdb02784aba277711d6dbc36a8e4a7a24ad876236c7dcae877f3b38 |
| hovercard-subject-tag | issue:186468849 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/12639/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9a0d32ed121e672e9301b8efb4fe2e9bf377cffe3ab1df9a831d823234ca1da5/angular/angular/issues/12639 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9a0d32ed121e672e9301b8efb4fe2e9bf377cffe3ab1df9a831d823234ca1da5/angular/angular/issues/12639 |
| og:image:alt | I'm submitting a ... (check one with "x") [X] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | steveblue |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width