Skip to content

Commit fc1b791

Browse files
committed
fix(view): ViewPort light should come from the direct parent
1 parent b953956 commit fc1b791

4 files changed

Lines changed: 52 additions & 3 deletions

File tree

modules/angular2/src/core/compiler/element_injector.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ export class ProtoElementInjector {
261261
return new ElementInjector(this, parent, host, eventCallbacks);
262262
}
263263

264+
directParent(): ProtoElementInjector {
265+
return this.distanceToParent < 2 ? this.parent : null;
266+
}
267+
264268
_createBinding(bindingOrType) {
265269
if (bindingOrType instanceof DirectiveBinding) {
266270
return bindingOrType;

modules/angular2/src/core/compiler/view.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ export class ProtoView {
401401
// viewPorts
402402
var viewPort = null;
403403
if (isPresent(binder.templateDirective)) {
404-
var destLightDom = this._parentElementLightDom(protoElementInjector, preBuiltObjects);
404+
var destLightDom = this._directParentElementLightDom(protoElementInjector, preBuiltObjects);
405405
viewPort = new ViewPort(view, element, binder.nestedProtoView, elementInjector, destLightDom);
406406
ListWrapper.push(viewPorts, viewPort);
407407
}
@@ -456,8 +456,8 @@ export class ProtoView {
456456
}
457457
}
458458

459-
_parentElementLightDom(protoElementInjector:ProtoElementInjector, preBuiltObjects:List):LightDom {
460-
var p = protoElementInjector.parent;
459+
_directParentElementLightDom(protoElementInjector:ProtoElementInjector, preBuiltObjects:List):LightDom {
460+
var p = protoElementInjector.directParent();
461461
return isPresent(p) ? preBuiltObjects[p.index].lightDom : null;
462462
}
463463

modules/angular2/test/core/compiler/element_injector_spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,26 @@ export function main() {
153153
return shadow;
154154
}
155155

156+
describe("ProtoElementInjector", () => {
157+
describe("direct parent", () => {
158+
it("should return parent proto injector when distance is 1", () => {
159+
var distance = 1;
160+
var protoParent = new ProtoElementInjector(null, 0, []);
161+
var protoChild = new ProtoElementInjector(protoParent, 1, [], false, distance);
162+
163+
expect(protoChild.directParent()).toEqual(protoParent);
164+
});
165+
166+
it("should return null otherwise", () => {
167+
var distance = 2;
168+
var protoParent = new ProtoElementInjector(null, 0, []);
169+
var protoChild = new ProtoElementInjector(protoParent, 1, [], false, distance);
170+
171+
expect(protoChild.directParent()).toEqual(null);
172+
});
173+
});
174+
});
175+
156176
describe("ElementInjector", function () {
157177
describe("instantiate", function () {
158178
it("should create an element injector", function () {

modules/angular2/test/core/compiler/shadow_dom/shadow_dom_emulation_integration_spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ export function main() {
7777
});
7878
});
7979

80+
it("should redistribute direct child viewports when the light dom changes", (done) => {
81+
var temp = '<multiple-content-tags>' +
82+
'<div><div template="manual" class="left">A</div></div>' +
83+
'<div>B</div>' +
84+
'</multiple-content-tags>';
85+
86+
compile(temp, (view, lc) => {
87+
var dir = view.elementInjectors[1].get(ManualTemplateDirective);
88+
89+
expect(view.nodes).toHaveText('(, B)');
90+
91+
dir.show();
92+
lc.tick();
93+
94+
expect(view.nodes).toHaveText('(, AB)');
95+
96+
dir.hide();
97+
lc.tick();
98+
99+
expect(view.nodes).toHaveText('(, B)');
100+
101+
done();
102+
});
103+
});
104+
80105
it("should redistribute when the light dom changes", (done) => {
81106
var temp = '<multiple-content-tags>' +
82107
'<div template="manual" class="left">A</div>' +

0 commit comments

Comments
 (0)