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
This commit is contained in:
Tobias Bosch 2015-10-29 16:23:13 -07:00
parent d1b54d6807
commit 39626a944d
2 changed files with 9 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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('<div>hello<a></a></div>', [createComp('div', ['*', 'a'])])))
.toEqual([['div', null], ['#text(hello)', 0], ['a', 1]]);
});
it('should only project direct child nodes', () => {
expect(humanizeContentProjection(
parse('<div><span><a></a></span><a></a></div>', [createComp('div', ['a'])])))