77 ElementRef ,
88 EnvironmentInjector ,
99 Injector ,
10+ Input ,
1011 QueryList ,
1112 TemplateRef ,
1213 ViewChild ,
@@ -15,6 +16,7 @@ import {
1516 createComponent ,
1617 createEnvironmentInjector ,
1718 inject ,
19+ inputBinding ,
1820} from '@angular/core' ;
1921import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2022import { DomPortalOutlet } from './dom-portal-outlet' ;
@@ -459,6 +461,25 @@ describe('Portals', () => {
459461
460462 expect ( fixture . nativeElement . textContent ) . toContain ( 'Projectable node' ) ;
461463 } ) ;
464+
465+ it ( 'should be able to pass bindings to the component' , ( ) => {
466+ let flavor = 'pepperoni' ;
467+ const componentPortal = new ComponentPortal ( PizzaMsg , null , null , null , [
468+ inputBinding ( 'flavor' , ( ) => flavor ) ,
469+ ] ) ;
470+
471+ fixture . componentInstance . selectedPortal = componentPortal ;
472+ fixture . changeDetectorRef . markForCheck ( ) ;
473+ fixture . detectChanges ( ) ;
474+
475+ const ref = fixture . componentInstance . portalOutlet . attachedRef as ComponentRef < PizzaMsg > ;
476+ expect ( ref . instance . flavor ) . toBe ( 'pepperoni' ) ;
477+
478+ flavor = 'cheese' ;
479+ fixture . changeDetectorRef . markForCheck ( ) ;
480+ fixture . detectChanges ( ) ;
481+ expect ( ref . instance . flavor ) . toBe ( 'cheese' ) ;
482+ } ) ;
462483 } ) ;
463484
464485 describe ( 'DomPortalOutlet' , ( ) => {
@@ -717,6 +738,17 @@ describe('Portals', () => {
717738 host . attachDomPortal ( new DomPortal ( fixture . componentInstance . domPortalContent ) ) ;
718739 expect ( host . hasAttached ( ) ) . toBe ( true ) ;
719740 } ) ;
741+
742+ it ( 'should be able to pass bindings to the component' , ( ) => {
743+ const portal = new ComponentPortal ( PizzaMsg , null , null , null , [
744+ inputBinding ( 'flavor' , ( ) => 'pepperoni' ) ,
745+ ] ) ;
746+
747+ const componentInstance : PizzaMsg = portal . attach ( host ) . instance ;
748+ someFixture . changeDetectorRef . markForCheck ( ) ;
749+ someFixture . detectChanges ( ) ;
750+ expect ( componentInstance . flavor ) . toBe ( 'pepperoni' ) ;
751+ } ) ;
720752 } ) ;
721753} ) ;
722754
@@ -744,6 +776,8 @@ class ChocolateInjector {
744776} )
745777class PizzaMsg {
746778 snack = inject ( Chocolate , { optional : true } ) ;
779+
780+ @Input ( ) flavor = 'unknown' ;
747781}
748782
749783/**
0 commit comments