ViewEncapsulation.Emulated is not working for dynamically created components
- Dominant language
- TypeScript
- Stars
- 101k
- Forks
- 27.5k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 288
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/angular/angular/blob/master/CONTRIBUTING.md#question
```
**Current behavior**
Angular 2 doesn't set `_ngcontent-*` attribute on the components created using `ViewContainerRef.createComponent()` when `ViewEncapsulation.Emulated` is used.
**Expected behavior**
Angular 2 sets `_ngcontent-*` attribute on the components created using `ViewContainerRef.createComponent()` when `ViewEncapsulation.Emulated` is used.
**Minimal reproduction of the problem with instructions**
~See reproduction example: http://plnkr.co/edit/0HF3A2muRlAVOEonJvs7~
Updated reproduction for Angular 6: https://stackblitz.com/edit/angular-uzjtlp
If you change view encapsulation to native (in browser supporting it) `my-dynamic-comp` will become red (which is expected behaviour). But with emulated view encapsulation it stays green. It's because `_ngcontent-*` attribute is not set on the dynamically created component's host element.
**What is the motivation / use case for changing the behavior?**
Emulated behaviour works different from native, so I assume it is a bug.
**Please tell us about your environment:**
- **Angular version:** 2.0.2
- **Browser:** all
- **Language:** TypeScript (but it may be relevant for others as well)
Contributor guide
Research direction
Start by reproducing the issue with ViewContainerRef.createComponent() using the linked StackBlitz example, then trace how dynamically created components receive their host attributes under ViewEncapsulation.Emulated. Done means the dynamic component's host element receives the expected _ngcontent-* attribute and the reproduction applies the same styling as native encapsulation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100