Skip to content

Commit a472eac

Browse files
committed
fix(content_projection): allow to project text nodes to a place without bindings
Fixes angular#3163 Closes angular#3179
1 parent 078475a commit a472eac

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export function mergeProtoViewsRecursively(protoViewRefs: List<RenderProtoViewRe
2727
mergeEmbeddedPvsIntoComponentOrRootPv(clonedProtoViews, hostViewAndBinderIndices);
2828
var fragments = [];
2929
mergeComponents(clonedProtoViews, hostViewAndBinderIndices, fragments);
30+
// Note: Need to remark parent elements of bound text nodes
31+
// so that we can find them later via queryBoundElements!
32+
markBoundTextNodeParentsAsBoundElements(clonedProtoViews);
3033

3134
// create a new root element with the changed fragments and elements
3235
var rootElement = createRootElementFromFragments(fragments);
@@ -86,6 +89,17 @@ function cloneProtoViews(protoViewRefs: List<RenderProtoViewRef | List<any>>,
8689
}
8790
}
8891

92+
function markBoundTextNodeParentsAsBoundElements(mergableProtoViews: ClonedProtoView[]) {
93+
mergableProtoViews.forEach((mergableProtoView) => {
94+
mergableProtoView.boundTextNodes.forEach((textNode) => {
95+
var parentNode = textNode.parentNode;
96+
if (isPresent(parentNode) && DOM.isElementNode(parentNode)) {
97+
DOM.addClass(parentNode, NG_BINDING_CLASS);
98+
}
99+
});
100+
});
101+
}
102+
89103
function indexBoundTextNodes(mergableProtoViews: ClonedProtoView[]): Map<Node, any> {
90104
var boundTextNodeMap = new Map();
91105
for (var pvIndex = 0; pvIndex < mergableProtoViews.length; pvIndex++) {

modules/angular2/test/render/dom/view/proto_view_merger_integration_spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ export function main() {
9898
'root', ['<a>{{b}}</a>', 'A(<ng-content></ng-content>)'],
9999
['<root class="ng-binding" idx="0"><a class="ng-binding" idx="1">A({0})</a></root>']));
100100

101+
it('should project text interpolation to elements without bindings',
102+
runAndAssert('root', ['<a>{{b}}</a>', '<div><ng-content></ng-content></div>'], [
103+
'<root class="ng-binding" idx="0"><a class="ng-binding" idx="1"><div class="ng-binding">{0}</div></a></root>'
104+
]));
105+
101106
it('should project elements',
102107
runAndAssert('root', ['<a><div></div></a>', 'A(<ng-content></ng-content>)'], [
103108
'<root class="ng-binding" idx="0"><a class="ng-binding" idx="1">A(<div></div>)</a></root>'

0 commit comments

Comments
 (0)