Skip to content

Commit

Permalink
feat(core): add injector to tuiDialog options
Browse files Browse the repository at this point in the history
  • Loading branch information
MillerSvt authored and splincode committed Dec 25, 2024
1 parent c786189 commit 297d564
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions projects/core/components/dialog/dialog.factory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {inject, INJECTOR} from '@angular/core';
import type {Injector} from '@angular/core';
import {assertInInjectionContext, inject, INJECTOR} from '@angular/core';
import {PolymorpheusComponent} from '@taiga-ui/polymorpheus';
import type {Observable} from 'rxjs';

Expand Down Expand Up @@ -41,17 +42,23 @@ type ExtractDialogResult<T, K extends keyof T = ContextKeys<T>> = [K] extends [n
? R
: void;

type Options<T> = Omit<TuiDialogOptions<T>, 'data'> & {injector: Injector};

export function tuiDialog<
T,
K extends ContextKeys<T>,
D extends ExtractDialogData<T, K>,
R extends ExtractDialogResult<T, K>,
>(
component: AssertNotMultipleContexts<T, K>,
options?: Partial<Omit<TuiDialogOptions<D>, 'data'>>,
{injector, ...options}: Partial<Options<D>> = {},
): (data: D) => Observable<R> {
const dialogService = inject(TuiDialogService);
const injector = inject(INJECTOR);
if (!injector) {
assertInInjectionContext(tuiDialog);
injector = inject(INJECTOR);
}

const dialogService = injector.get(TuiDialogService);

return (data) =>
dialogService.open(
Expand Down

0 comments on commit 297d564

Please sign in to comment.