X Tutup
Skip to content

Commit 39626a9

Browse files
committed
fix(ng-content): wildcard ng-content has to go last.
This was the case before the new compiler landed and should be preserved. Related to #4598 Closes #5016
1 parent d1b54d6 commit 39626a9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

modules/angular2/src/core/compiler/template_parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,12 @@ class Component {
655655

656656
findNgContentIndex(selector: CssSelector): number {
657657
var ngContentIndices = [];
658-
if (isPresent(this.wildcardNgContentIndex)) {
659-
ngContentIndices.push(this.wildcardNgContentIndex);
660-
}
661658
this.ngContentIndexMatcher.match(
662659
selector, (selector, ngContentIndex) => { ngContentIndices.push(ngContentIndex); });
663660
ListWrapper.sort(ngContentIndices);
661+
if (isPresent(this.wildcardNgContentIndex)) {
662+
ngContentIndices.push(this.wildcardNgContentIndex);
663+
}
664664
return ngContentIndices.length > 0 ? ngContentIndices[0] : null;
665665
}
666666
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,12 @@ There is no directive with "exportAs" set to "dirA" at TestComp > div:nth-child(
754754
.toEqual([['div', null], ['#text(hello)', 2], ['b', 1], ['a', 0]]);
755755
});
756756

757+
it('should project into wildcard ng-content last', () => {
758+
expect(humanizeContentProjection(
759+
parse('<div>hello<a></a></div>', [createComp('div', ['*', 'a'])])))
760+
.toEqual([['div', null], ['#text(hello)', 0], ['a', 1]]);
761+
});
762+
757763
it('should only project direct child nodes', () => {
758764
expect(humanizeContentProjection(
759765
parse('<div><span><a></a></span><a></a></div>', [createComp('div', ['a'])])))

0 commit comments

Comments
 (0)
X Tutup