X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions modules/angular2/src/core/render/view_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,28 @@ class RenderViewBuilder<N> implements RenderCommandVisitor {
componentTemplate: RenderComponentTemplate): N {
var el: N = context.consumeInplaceElement();
var attrNameAndValues = cmd.attrNameAndValues;
if (this.template.encapsulation === ViewEncapsulation.Emulated) {
var templateEmulatedEncapsulation = this.template.encapsulation === ViewEncapsulation.Emulated;
var componentEmulatedEncapsulation =
isPresent(componentTemplate) &&
componentTemplate.encapsulation === ViewEncapsulation.Emulated;
var newAttrLength = attrNameAndValues.length + (templateEmulatedEncapsulation ? 2 : 0) +
(componentEmulatedEncapsulation ? 2 : 0);
if (newAttrLength > attrNameAndValues.length) {
// Note: Need to clone attrNameAndValues to make it writable!
if (isPresent(componentTemplate)) {
attrNameAndValues = attrNameAndValues.concat([
_shimContentAttribute(this.template.shortId),
'',
_shimHostAttribute(componentTemplate.shortId),
''
]);
} else {
attrNameAndValues =
attrNameAndValues.concat([_shimContentAttribute(this.template.shortId), '']);
var newAttrNameAndValues = ListWrapper.createFixedSize(newAttrLength);
var attrIndex;
for (attrIndex = 0; attrIndex < attrNameAndValues.length; attrIndex++) {
newAttrNameAndValues[attrIndex] = attrNameAndValues[attrIndex];
}
if (templateEmulatedEncapsulation) {
newAttrNameAndValues[attrIndex++] = _shimContentAttribute(this.template.shortId);
newAttrNameAndValues[attrIndex++] = '';
}
if (componentEmulatedEncapsulation) {
newAttrNameAndValues[attrIndex++] = _shimHostAttribute(componentTemplate.shortId);
newAttrNameAndValues[attrIndex++] = '';
}
attrNameAndValues = newAttrNameAndValues;
}
if (isPresent(el)) {
context.factory.mergeElement(el, attrNameAndValues);
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/test/core/render/view_factory_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,11 @@ export function main() {
'innerComp', 'innerid', ViewEncapsulation.Emulated,
[beginElement('div', [], [], false, null), endElement()], []));
var view = createRenderView(
encapsulatedTpl, [beginComponent('my-comp', [], [], null, '0'), endComponent()],
defaultCmpTpl, [beginComponent('my-comp', [], [], null, '0'), endComponent()],
null, nodeFactory);
expect(stringifyFragment(view.fragments[0].nodes))
.toEqual(
'<my-comp _ngcontent-shortid="" _nghost-innerid=""><div _ngcontent-innerid=""></div></my-comp>');
'<my-comp _nghost-innerid=""><div _ngcontent-innerid=""></div></my-comp>');
});
});
});
Expand Down
X Tutup