MCPcopy Create free account
hub / github.com/angular/components / _createInjector

Method _createInjector

src/cdk/dialog/dialog.ts:328–360  ·  view source on GitHub ↗

* Creates a custom injector to be used inside the dialog. This allows a component loaded inside * of a dialog to close itself and, optionally, to return a value. * @param config Config object that is used to construct the dialog. * @param dialogRef Reference to the dialog being opened. *

(
    config: DialogConfig<D, DialogRef<R, C>>,
    dialogRef: DialogRef<R, C>,
    dialogContainer: DialogContainer,
    fallbackInjector: Injector | undefined,
  )

Source from the content-addressed store, hash-verified

326 * @returns The custom injector that can be used inside the dialog.
327 */
328 private _createInjector<R, D, C>(
329 config: DialogConfig<D, DialogRef<R, C>>,
330 dialogRef: DialogRef<R, C>,
331 dialogContainer: DialogContainer,
332 fallbackInjector: Injector | undefined,
333 ): Injector {
334 const userInjector = config.injector || config.viewContainerRef?.injector;
335 const providers: StaticProvider[] = [
336 {provide: DIALOG_DATA, useValue: config.data},
337 {provide: DialogRef, useValue: dialogRef},
338 ];
339
340 if (config.providers) {
341 if (typeof config.providers === 'function') {
342 providers.push(...config.providers(dialogRef, config, dialogContainer));
343 } else {
344 providers.push(...config.providers);
345 }
346 }
347
348 if (
349 config.direction &&
350 (!userInjector ||
351 !userInjector.get<Directionality | null>(Directionality, null, {optional: true}))
352 ) {
353 providers.push({
354 provide: Directionality,
355 useValue: getDirectionality(config.direction),
356 });
357 }
358
359 return Injector.create({parent: userInjector || fallbackInjector, providers});
360 }
361
362 /**
363 * Removes a dialog from the array of open dialogs.

Callers 1

_attachDialogContentMethod · 0.95

Calls 3

getDirectionalityFunction · 0.85
pushMethod · 0.65
createMethod · 0.45

Tested by

no test coverage detected