X Tutup
Skip to content

Commit b44b06c

Browse files
committed
fix(projection): allow to project to a non text node
We already had a test for this, but too low level that it did not catch this null value in `hasNativeShadowRoot` Fixes #3230 Closes #3241
1 parent 5ec67ee commit b44b06c

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

modules/angular2/src/render/dom/view/element_binder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {AST} from 'angular2/change_detection';
22
import {List, ListWrapper} from 'angular2/src/facade/collection';
3+
import {isPresent} from 'angular2/src/facade/lang';
34

45
export class DomElementBinder {
56
textNodeIndices: List<number>;
@@ -23,7 +24,7 @@ export class DomElementBinder {
2324
this.eventLocals = eventLocals;
2425
this.localEvents = localEvents;
2526
this.globalEvents = globalEvents;
26-
this.hasNativeShadowRoot = hasNativeShadowRoot;
27+
this.hasNativeShadowRoot = isPresent(hasNativeShadowRoot) ? hasNativeShadowRoot : false;
2728
}
2829
}
2930

modules/angular2/src/render/dom/view/proto_view_merger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ function updateElementBinderTextNodeIndices(elementBinder: DomElementBinder,
339339
eventLocals: null,
340340
localEvents: [],
341341
globalEvents: [],
342-
hasNativeShadowRoot: null
342+
hasNativeShadowRoot: false
343343
});
344344
} else {
345345
result = new DomElementBinder({

modules/angular2/test/core/compiler/projection_integration_spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,25 @@ export function main() {
7373
});
7474
}));
7575

76+
it('should support projecting text interpolation to a non bound element',
77+
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
78+
tcb.overrideView(
79+
Simple,
80+
new viewAnn.View(
81+
{template: 'SIMPLE(<div><ng-content></ng-content></div>)', directives: []}))
82+
.overrideView(
83+
MainComp,
84+
new viewAnn.View({template: '<simple>{{text}}</simple>', directives: [Simple]}))
85+
.createAsync(MainComp)
86+
.then((main) => {
87+
88+
main.componentInstance.text = 'A';
89+
main.detectChanges();
90+
expect(main.nativeElement).toHaveText('SIMPLE(A)');
91+
async.done();
92+
});
93+
}));
94+
7695
it('should not show the light dom even if there is no content tag',
7796
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
7897
tcb.overrideView(MainComp,

0 commit comments

Comments
 (0)
X Tutup