@@ -13,12 +13,16 @@ import {SpyLocation} from '@angular/common/testing';
1313import {
1414 Component ,
1515 ComponentRef ,
16+ createNgModuleRef ,
1617 Directive ,
18+ Injectable ,
1719 Injector ,
20+ NgModule ,
1821 TemplateRef ,
1922 ViewChild ,
2023 ViewContainerRef ,
2124 ViewEncapsulation ,
25+ forwardRef ,
2226 inject ,
2327} from '@angular/core' ;
2428import {
@@ -987,6 +991,25 @@ describe('MatBottomSheet with default options', () => {
987991 } ) ) ;
988992} ) ;
989993
994+ describe ( 'MatBottomSheet with explicit injector provided' , ( ) => {
995+ let overlayContainerElement : HTMLElement ;
996+ let fixture : ComponentFixture < ModuleBoundBottomSheetParentComponent > ;
997+
998+ beforeEach ( fakeAsync ( ( ) => {
999+ overlayContainerElement = TestBed . inject ( OverlayContainer ) . getContainerElement ( ) ;
1000+ fixture = TestBed . createComponent ( ModuleBoundBottomSheetParentComponent ) ;
1001+ } ) ) ;
1002+
1003+ it ( 'should use the standalone injector and render the bottom sheet successfully' , ( ) => {
1004+ fixture . componentInstance . openBottomSheet ( ) ;
1005+ fixture . detectChanges ( ) ;
1006+
1007+ expect (
1008+ overlayContainerElement . querySelector ( 'module-bound-bottom-sheet-child-component' ) ! . innerHTML ,
1009+ ) . toEqual ( '<p>Pasta</p>' ) ;
1010+ } ) ;
1011+ } ) ;
1012+
9901013@Directive ( {
9911014 selector : 'dir-with-view-container' ,
9921015} )
@@ -1066,3 +1089,46 @@ class BottomSheetWithInjectedData {
10661089 encapsulation : ViewEncapsulation . ShadowDom ,
10671090} )
10681091class ShadowDomComponent { }
1092+
1093+ @Component ( {
1094+ template : '' ,
1095+ } )
1096+ class ModuleBoundBottomSheetParentComponent {
1097+ private _injector = inject ( Injector ) ;
1098+ private _bottomSheet = inject ( MatBottomSheet ) ;
1099+
1100+ openBottomSheet ( ) : void {
1101+ const ngModuleRef = createNgModuleRef (
1102+ ModuleBoundBottomSheetModule ,
1103+ /* parentInjector */ this . _injector ,
1104+ ) ;
1105+
1106+ this . _bottomSheet . open ( ModuleBoundBottomSheetComponent , { injector : ngModuleRef . injector } ) ;
1107+ }
1108+ }
1109+
1110+ @Injectable ( )
1111+ class ModuleBoundBottomSheetService {
1112+ name = 'Pasta' ;
1113+ }
1114+
1115+ @Component ( {
1116+ template :
1117+ '<module-bound-bottom-sheet-child-component></module-bound-bottom-sheet-child-component>' ,
1118+ imports : [ forwardRef ( ( ) => ModuleBoundBottomSheetChildComponent ) ] ,
1119+ } )
1120+ class ModuleBoundBottomSheetComponent { }
1121+
1122+ @Component ( {
1123+ selector : 'module-bound-bottom-sheet-child-component' ,
1124+ template : '<p>{{service.name}}</p>' ,
1125+ } )
1126+ class ModuleBoundBottomSheetChildComponent {
1127+ service = inject ( ModuleBoundBottomSheetService ) ;
1128+ }
1129+
1130+ @NgModule ( {
1131+ imports : [ ModuleBoundBottomSheetComponent , ModuleBoundBottomSheetChildComponent ] ,
1132+ providers : [ ModuleBoundBottomSheetService ] ,
1133+ } )
1134+ class ModuleBoundBottomSheetModule { }
0 commit comments