Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(content_tag): removes elements no longer selected by the content …
Browse files Browse the repository at this point in the history
…tag from DOM

In transcluding mode, elements that were previously matched by a content
tag's select attribute were not removed from the DOM when the elements
were no longer selected. This patch fixes the issue.
  • Loading branch information
goderbauer authored and rkirov committed Feb 11, 2015
1 parent 43e00e5 commit 011d65f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/core_dom/content_tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class _RenderedTranscludingContent implements _ContentStrategy {
void insert(Iterable<dom.Node> nodes){
final p = _endScript.parent;
if (p != null && ! _equalToCurrNodes(nodes)) {
_removeNodesBetweenScriptTags();
_currNodes = nodes.toList();
p.insertAllBefore(nodes, _endScript);
}
Expand Down Expand Up @@ -78,7 +79,7 @@ class _RenderedTranscludingContent implements _ContentStrategy {
void _removeNodesBetweenScriptTags() {
final p = _beginScript.parent;
for (var next = _beginScript.nextNode;
next.nodeType != dom.Node.ELEMENT_NODE || next.attributes["ng/content"] != null;
next.nodeType != dom.Node.ELEMENT_NODE || next.attributes["type"] != "ng/content";
next = _beginScript.nextNode) {
p.nodes.remove(next);
}
Expand Down
34 changes: 34 additions & 0 deletions test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ void main() {
..bind(SimpleAttachComponent)
..bind(SimpleComponent)
..bind(MultipleContentTagsComponent)
..bind(SelectableContentComponent)
..bind(ConditionalContentComponent)
..bind(ExprAttrComponent)
..bind(LogElementComponent)
Expand Down Expand Up @@ -478,6 +479,32 @@ void main() {
expect(element).toHaveText('OUTER(INNER(ABC))');
}));

it("should remove elements that no longer match the selector", async((){
var element = _.compile(r'<div>'
'<selectable-content-tag>'
'<div ng-class="{\'selected\':isSelected}">A</div>'
'<div class="selected">B</div>'
'<div>C</div>'
'</selectable-content-tag>'
'</div>');
document.body.append(element);

microLeap();
_.rootScope.apply();

_.rootScope.context["isSelected"] = true;
microLeap();
_.rootScope.apply();

expect(element).toHaveText('(AB)');

_.rootScope.context["isSelected"] = false;
microLeap();
_.rootScope.apply();

expect(element).toHaveText('(B)');
}));

it("should support nesting with content being direct child of a nested component", async((){
// platform.js does not emulate this behavior, so the test fails on firefox.
// Remove the if when this is fixed.
Expand Down Expand Up @@ -1319,6 +1346,13 @@ class SimpleComponent {
var name = 'INNER';
}

@Component(
selector: 'selectable-content-tag',
template: r'(<content select=".selected"></content>)')
class SelectableContentComponent {
SelectableContentComponent();
}

@Component(
selector: 'multiple-content-tags',
template: r'(<content select=".left"></content>, <content></content>)')
Expand Down

0 comments on commit 011d65f

Please sign in to comment.