Skip to content

Commit bf2723c

Browse files
vapkseldulary
authored andcommitted
fix(cdk/dialog): use config injector if provided (#25332)
Co-authored-by: Laurent Dulary <[email protected]> (cherry picked from commit ea4e203)
1 parent b029dea commit bf2723c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/cdk/dialog/dialog.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Component,
1212
Directive,
1313
Inject,
14+
InjectionToken,
1415
Injector,
1516
TemplateRef,
1617
ViewChild,
@@ -125,6 +126,15 @@ describe('Dialog', () => {
125126
);
126127
});
127128

129+
it('should use custom injector', () => {
130+
const token = new InjectionToken<string>('message');
131+
const injector = Injector.create({providers: [{provide: token, useValue: 'hello'}]});
132+
const dialogRef = dialog.open(PizzaMsg, {injector});
133+
viewContainerFixture.detectChanges();
134+
135+
expect(dialogRef.componentInstance?.dialogInjector.get(token)).toBe('hello');
136+
});
137+
128138
it('should open a dialog with a component and no ViewContainerRef', () => {
129139
let dialogRef = dialog.open(PizzaMsg);
130140

src/cdk/dialog/dialog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class Dialog implements OnDestroy {
333333
});
334334
}
335335

336-
return Injector.create({parent: userInjector || this._injector, providers});
336+
return Injector.create({parent: config.injector || userInjector || this._injector, providers});
337337
}
338338

339339
/**

0 commit comments

Comments
 (0)