fix(platform-browser): insert APP_ID in styles, contentAttr and hostAttr (#17745)

PR Close #17745
This commit is contained in:
Peter Johan Salomonsen
2017-06-24 21:09:38 +02:00
committed by Igor Minar
parent 3ea8d651cc
commit 712d60e467
7 changed files with 19 additions and 16 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ export const BROWSER_MODULE_PROVIDERS: StaticProvider[] = [
{
provide: DomRendererFactory2,
useClass: DomRendererFactory2,
deps: [EventManager, DomSharedStylesHost]
deps: [EventManager, DomSharedStylesHost, APP_ID]
},
{provide: RendererFactory2, useExisting: DomRendererFactory2},
{provide: SharedStylesHost, useExisting: DomSharedStylesHost},
@@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Injectable, Renderer2, RendererFactory2, RendererStyleFlags2, RendererType2, ViewEncapsulation} from '@angular/core';
import {APP_ID, Inject, Injectable, Renderer2, RendererFactory2, RendererStyleFlags2, RendererType2, ViewEncapsulation} from '@angular/core';
import {EventManager} from './events/event_manager';
import {DomSharedStylesHost} from './shared_styles_host';
@@ -63,7 +63,9 @@ export class DomRendererFactory2 implements RendererFactory2 {
private rendererByCompId = new Map<string, Renderer2>();
private defaultRenderer: Renderer2;
constructor(private eventManager: EventManager, private sharedStylesHost: DomSharedStylesHost) {
constructor(
private eventManager: EventManager, private sharedStylesHost: DomSharedStylesHost,
@Inject(APP_ID) private appId: string) {
this.defaultRenderer = new DefaultDomRenderer2(eventManager);
}
@@ -75,8 +77,8 @@ export class DomRendererFactory2 implements RendererFactory2 {
case ViewEncapsulation.Emulated: {
let renderer = this.rendererByCompId.get(type.id);
if (!renderer) {
renderer =
new EmulatedEncapsulationDomRenderer2(this.eventManager, this.sharedStylesHost, type);
renderer = new EmulatedEncapsulationDomRenderer2(
this.eventManager, this.sharedStylesHost, type, this.appId);
this.rendererByCompId.set(type.id, renderer);
}
(<EmulatedEncapsulationDomRenderer2>renderer).applyToHost(element);
@@ -243,13 +245,13 @@ class EmulatedEncapsulationDomRenderer2 extends DefaultDomRenderer2 {
constructor(
eventManager: EventManager, sharedStylesHost: DomSharedStylesHost,
private component: RendererType2) {
private component: RendererType2, appId: string) {
super(eventManager);
const styles = flattenStyles(component.id, component.styles, []);
const styles = flattenStyles(appId + '-' + component.id, component.styles, []);
sharedStylesHost.addStyles(styles);
this.contentAttr = shimContentAttribute(component.id);
this.hostAttr = shimHostAttribute(component.id);
this.contentAttr = shimContentAttribute(appId + '-' + component.id);
this.hostAttr = shimHostAttribute(appId + '-' + component.id);
}
applyToHost(element: any) { super.setAttribute(element, this.hostAttr, ''); }