From 39626a944d593f049029a4390ca22fadf517c708 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 29 Oct 2015 16:23:13 -0700 Subject: [PATCH] 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 --- modules/angular2/src/core/compiler/template_parser.ts | 6 +++--- modules/angular2/test/core/compiler/template_parser_spec.ts | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/angular2/src/core/compiler/template_parser.ts b/modules/angular2/src/core/compiler/template_parser.ts index ce9083d52e..8553e3e182 100644 --- a/modules/angular2/src/core/compiler/template_parser.ts +++ b/modules/angular2/src/core/compiler/template_parser.ts @@ -655,12 +655,12 @@ class Component { findNgContentIndex(selector: CssSelector): number { var ngContentIndices = []; - if (isPresent(this.wildcardNgContentIndex)) { - ngContentIndices.push(this.wildcardNgContentIndex); - } this.ngContentIndexMatcher.match( selector, (selector, ngContentIndex) => { ngContentIndices.push(ngContentIndex); }); ListWrapper.sort(ngContentIndices); + if (isPresent(this.wildcardNgContentIndex)) { + ngContentIndices.push(this.wildcardNgContentIndex); + } return ngContentIndices.length > 0 ? ngContentIndices[0] : null; } } diff --git a/modules/angular2/test/core/compiler/template_parser_spec.ts b/modules/angular2/test/core/compiler/template_parser_spec.ts index 2db9f1aece..02ddefdf3b 100644 --- a/modules/angular2/test/core/compiler/template_parser_spec.ts +++ b/modules/angular2/test/core/compiler/template_parser_spec.ts @@ -754,6 +754,12 @@ There is no directive with "exportAs" set to "dirA" at TestComp > div:nth-child( .toEqual([['div', null], ['#text(hello)', 2], ['b', 1], ['a', 0]]); }); + it('should project into wildcard ng-content last', () => { + expect(humanizeContentProjection( + parse('
hello
', [createComp('div', ['*', 'a'])]))) + .toEqual([['div', null], ['#text(hello)', 0], ['a', 1]]); + }); + it('should only project direct child nodes', () => { expect(humanizeContentProjection( parse('
', [createComp('div', ['a'])])))