X Tutup
Skip to content

Commit 344776f

Browse files
committed
fix(renderer): apply host element encapsulation also if the parent component is not encapsulated.
Closes #5240
1 parent a3e6406 commit 344776f

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

modules/angular2/src/core/render/view_factory.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,28 @@ class RenderViewBuilder<N> implements RenderCommandVisitor {
225225
componentTemplate: RenderComponentTemplate): N {
226226
var el: N = context.consumeInplaceElement();
227227
var attrNameAndValues = cmd.attrNameAndValues;
228-
if (this.template.encapsulation === ViewEncapsulation.Emulated) {
228+
var templateEmulatedEncapsulation = this.template.encapsulation === ViewEncapsulation.Emulated;
229+
var componentEmulatedEncapsulation =
230+
isPresent(componentTemplate) &&
231+
componentTemplate.encapsulation === ViewEncapsulation.Emulated;
232+
var newAttrLength = attrNameAndValues.length + (templateEmulatedEncapsulation ? 2 : 0) +
233+
(componentEmulatedEncapsulation ? 2 : 0);
234+
if (newAttrLength > attrNameAndValues.length) {
229235
// Note: Need to clone attrNameAndValues to make it writable!
230-
if (isPresent(componentTemplate)) {
231-
attrNameAndValues = attrNameAndValues.concat([
232-
_shimContentAttribute(this.template.shortId),
233-
'',
234-
_shimHostAttribute(componentTemplate.shortId),
235-
''
236-
]);
237-
} else {
238-
attrNameAndValues =
239-
attrNameAndValues.concat([_shimContentAttribute(this.template.shortId), '']);
236+
var newAttrNameAndValues = ListWrapper.createFixedSize(newAttrLength);
237+
var attrIndex;
238+
for (attrIndex = 0; attrIndex < attrNameAndValues.length; attrIndex++) {
239+
newAttrNameAndValues[attrIndex] = attrNameAndValues[attrIndex];
240+
}
241+
if (templateEmulatedEncapsulation) {
242+
newAttrNameAndValues[attrIndex++] = _shimContentAttribute(this.template.shortId);
243+
newAttrNameAndValues[attrIndex++] = '';
244+
}
245+
if (componentEmulatedEncapsulation) {
246+
newAttrNameAndValues[attrIndex++] = _shimHostAttribute(componentTemplate.shortId);
247+
newAttrNameAndValues[attrIndex++] = '';
240248
}
249+
attrNameAndValues = newAttrNameAndValues;
241250
}
242251
if (isPresent(el)) {
243252
context.factory.mergeElement(el, attrNameAndValues);

modules/angular2/test/core/render/view_factory_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,11 @@ export function main() {
611611
'innerComp', 'innerid', ViewEncapsulation.Emulated,
612612
[beginElement('div', [], [], false, null), endElement()], []));
613613
var view = createRenderView(
614-
encapsulatedTpl, [beginComponent('my-comp', [], [], null, '0'), endComponent()],
614+
defaultCmpTpl, [beginComponent('my-comp', [], [], null, '0'), endComponent()],
615615
null, nodeFactory);
616616
expect(stringifyFragment(view.fragments[0].nodes))
617617
.toEqual(
618-
'<my-comp _ngcontent-shortid="" _nghost-innerid=""><div _ngcontent-innerid=""></div></my-comp>');
618+
'<my-comp _nghost-innerid=""><div _ngcontent-innerid=""></div></my-comp>');
619619
});
620620
});
621621
});

0 commit comments

Comments
 (0)
X Tutup