forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ivy): ViewRef.rootNodes not including projected nodes (angular#28951
) Currently if an embedded view contains projected nodes, its `rootNodes` array will include `null` instead of the root nodes inside the projection slot. This manifested itself in one of the Material unit tests where we stamp out a template and then move its `rootNodes` into the overlay container. This PR is related to FW-1087. PR Close angular#28951
- Loading branch information
Showing
3 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Component, TemplateRef, ViewChild, ViewContainerRef} from '@angular/core'; | ||
import {TestBed} from '@angular/core/testing'; | ||
import {expect} from '@angular/platform-browser/testing/src/matchers'; | ||
|
||
describe('TemplateRef', () => { | ||
describe('rootNodes', () => { | ||
it('should include projected nodes in rootNodes', () => { | ||
@Component({ | ||
selector: 'menu-content', | ||
template: ` | ||
<ng-template> | ||
Header | ||
<ng-content></ng-content> | ||
</ng-template> | ||
`, | ||
exportAs: 'menuContent' | ||
}) | ||
class MenuContent { | ||
@ViewChild(TemplateRef) template !: TemplateRef<any>; | ||
} | ||
|
||
@Component({ | ||
template: ` | ||
<menu-content #menu="menuContent"> | ||
<button>Item one</button> | ||
<button>Item two</button> | ||
</menu-content> | ||
` | ||
}) | ||
class App { | ||
@ViewChild(MenuContent) content !: MenuContent; | ||
|
||
constructor(public viewContainerRef: ViewContainerRef) {} | ||
} | ||
|
||
TestBed.configureTestingModule({declarations: [MenuContent, App]}); | ||
const fixture = TestBed.createComponent(App); | ||
fixture.detectChanges(); | ||
|
||
const instance = fixture.componentInstance; | ||
const viewRef = instance.viewContainerRef.createEmbeddedView(instance.content.template); | ||
const rootNodeTextContent = viewRef.rootNodes.map(node => node && node.textContent.trim()) | ||
.filter(text => text !== ''); | ||
|
||
expect(rootNodeTextContent).toEqual(['Header', 'Item one', 'Item two']); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters