diff --git a/modules/@angular/platform-browser/src/dom/dom_renderer.ts b/modules/@angular/platform-browser/src/dom/dom_renderer.ts index 950522dd50..434b396a13 100644 --- a/modules/@angular/platform-browser/src/dom/dom_renderer.ts +++ b/modules/@angular/platform-browser/src/dom/dom_renderer.ts @@ -126,6 +126,7 @@ export class DomRenderer implements Renderer { let nodesParent: Element|DocumentFragment; if (this.componentProto.encapsulation === ViewEncapsulation.Native) { nodesParent = (hostElement as any).createShadowRoot(); + this._rootRenderer.sharedStylesHost.addHost(nodesParent); for (let i = 0; i < this._styles.length; i++) { const styleEl = document.createElement('style'); styleEl.textContent = this._styles[i]; diff --git a/modules/@angular/platform-browser/test/dom/dom_renderer_spec.ts b/modules/@angular/platform-browser/test/dom/dom_renderer_spec.ts index e64993bac7..dc0618b6bf 100644 --- a/modules/@angular/platform-browser/test/dom/dom_renderer_spec.ts +++ b/modules/@angular/platform-browser/test/dom/dom_renderer_spec.ts @@ -8,7 +8,6 @@ import {CommonModule} from '@angular/common'; import {Component, NgModule, ViewEncapsulation} from '@angular/core'; import {TestBed} from '@angular/core/testing'; -import {describe, it} from '@angular/core/testing/testing_internal'; import {BrowserModule} from '@angular/platform-browser'; import {By} from '@angular/platform-browser/src/dom/debug/by'; import {browserDetection} from '@angular/platform-browser/testing/browser_util'; @@ -21,23 +20,37 @@ export function main() { // other browsers don't support shadow dom if (browserDetection.isChromeDesktop) { - it('should add only styles with native encapsulation to the shadow DOM', () => { - const fixture = TestBed.createComponent(SomeApp); - fixture.detectChanges(); + it('should allow to style components with emulated encapsulation and no encapsulation inside of components with shadow DOM', + () => { + TestBed.overrideComponent(CmpEncapsulationNative, { + set: { + template: + '