@@ -13,12 +13,16 @@ import {SpyLocation} from '@angular/common/testing';
13
13
import {
14
14
Component ,
15
15
ComponentRef ,
16
+ createNgModuleRef ,
16
17
Directive ,
18
+ Injectable ,
17
19
Injector ,
20
+ NgModule ,
18
21
TemplateRef ,
19
22
ViewChild ,
20
23
ViewContainerRef ,
21
24
ViewEncapsulation ,
25
+ forwardRef ,
22
26
inject ,
23
27
} from '@angular/core' ;
24
28
import {
@@ -987,6 +991,25 @@ describe('MatBottomSheet with default options', () => {
987
991
} ) ) ;
988
992
} ) ;
989
993
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
+
990
1013
@Directive ( {
991
1014
selector : 'dir-with-view-container' ,
992
1015
} )
@@ -1066,3 +1089,46 @@ class BottomSheetWithInjectedData {
1066
1089
encapsulation : ViewEncapsulation . ShadowDom ,
1067
1090
} )
1068
1091
class 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