fix(content_projection): allow to project text nodes to a place without bindings
Fixes #3163 Closes #3179
This commit is contained in:
parent
078475a082
commit
a472eacc07
|
@ -27,6 +27,9 @@ export function mergeProtoViewsRecursively(protoViewRefs: List<RenderProtoViewRe
|
||||||
mergeEmbeddedPvsIntoComponentOrRootPv(clonedProtoViews, hostViewAndBinderIndices);
|
mergeEmbeddedPvsIntoComponentOrRootPv(clonedProtoViews, hostViewAndBinderIndices);
|
||||||
var fragments = [];
|
var fragments = [];
|
||||||
mergeComponents(clonedProtoViews, hostViewAndBinderIndices, fragments);
|
mergeComponents(clonedProtoViews, hostViewAndBinderIndices, fragments);
|
||||||
|
// Note: Need to remark parent elements of bound text nodes
|
||||||
|
// so that we can find them later via queryBoundElements!
|
||||||
|
markBoundTextNodeParentsAsBoundElements(clonedProtoViews);
|
||||||
|
|
||||||
// create a new root element with the changed fragments and elements
|
// create a new root element with the changed fragments and elements
|
||||||
var rootElement = createRootElementFromFragments(fragments);
|
var rootElement = createRootElementFromFragments(fragments);
|
||||||
|
@ -86,6 +89,17 @@ function cloneProtoViews(protoViewRefs: List<RenderProtoViewRef | List<any>>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function markBoundTextNodeParentsAsBoundElements(mergableProtoViews: ClonedProtoView[]) {
|
||||||
|
mergableProtoViews.forEach((mergableProtoView) => {
|
||||||
|
mergableProtoView.boundTextNodes.forEach((textNode) => {
|
||||||
|
var parentNode = textNode.parentNode;
|
||||||
|
if (isPresent(parentNode) && DOM.isElementNode(parentNode)) {
|
||||||
|
DOM.addClass(parentNode, NG_BINDING_CLASS);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function indexBoundTextNodes(mergableProtoViews: ClonedProtoView[]): Map<Node, any> {
|
function indexBoundTextNodes(mergableProtoViews: ClonedProtoView[]): Map<Node, any> {
|
||||||
var boundTextNodeMap = new Map();
|
var boundTextNodeMap = new Map();
|
||||||
for (var pvIndex = 0; pvIndex < mergableProtoViews.length; pvIndex++) {
|
for (var pvIndex = 0; pvIndex < mergableProtoViews.length; pvIndex++) {
|
||||||
|
|
|
@ -98,6 +98,11 @@ export function main() {
|
||||||
'root', ['<a>{{b}}</a>', 'A(<ng-content></ng-content>)'],
|
'root', ['<a>{{b}}</a>', 'A(<ng-content></ng-content>)'],
|
||||||
['<root class="ng-binding" idx="0"><a class="ng-binding" idx="1">A({0})</a></root>']));
|
['<root class="ng-binding" idx="0"><a class="ng-binding" idx="1">A({0})</a></root>']));
|
||||||
|
|
||||||
|
it('should project text interpolation to elements without bindings',
|
||||||
|
runAndAssert('root', ['<a>{{b}}</a>', '<div><ng-content></ng-content></div>'], [
|
||||||
|
'<root class="ng-binding" idx="0"><a class="ng-binding" idx="1"><div class="ng-binding">{0}</div></a></root>'
|
||||||
|
]));
|
||||||
|
|
||||||
it('should project elements',
|
it('should project elements',
|
||||||
runAndAssert('root', ['<a><div></div></a>', 'A(<ng-content></ng-content>)'], [
|
runAndAssert('root', ['<a><div></div></a>', 'A(<ng-content></ng-content>)'], [
|
||||||
'<root class="ng-binding" idx="0"><a class="ng-binding" idx="1">A(<div></div>)</a></root>'
|
'<root class="ng-binding" idx="0"><a class="ng-binding" idx="1">A(<div></div>)</a></root>'
|
||||||
|
|
Loading…
Reference in New Issue