Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/framework/theme/components/dialog/dialog-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { InjectionToken, ViewContainerRef } from '@angular/core';
import { InjectionToken, InputSignal, Signal, ViewContainerRef } from '@angular/core';


export const NB_DIALOG_CONFIG = new InjectionToken<NbDialogConfig>('Default dialog options');

type DialogData<T> = {
[K in keyof T]: ExtractInputSignalType<T[K]>;
};

type ExtractInputSignalType<Type> = Type extends InputSignal<infer X> ? X : ExcludeSignal<Type>;

type ExcludeSignal<Type> = Type extends Signal<unknown> ? never : Type;

/**
* Describes all available options that may be passed to the NbDialogService.
* */
Expand Down Expand Up @@ -56,7 +64,7 @@ export class NbDialogConfig<D = any> {
*/
viewContainerRef: ViewContainerRef;

context: D;
context: DialogData<D>;

constructor(config: Partial<NbDialogConfig>) {
Object.assign(this, config);
Expand Down
13 changes: 11 additions & 2 deletions src/framework/theme/components/dialog/dialog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { Inject, Injectable, Injector, TemplateRef, Type } from '@angular/core';
import { Inject, Injectable, Injector, signal, TemplateRef, Type } from '@angular/core';
import { fromEvent as observableFromEvent } from 'rxjs';
import { filter, takeUntil } from 'rxjs/operators';

Expand All @@ -20,6 +20,7 @@ import { NB_DOCUMENT } from '../../theme.options';
import { NB_DIALOG_CONFIG, NbDialogConfig } from './dialog-config';
import { NbDialogRef } from './dialog-ref';
import { NbDialogContainerComponent } from './dialog-container';
import { SIGNAL } from '@angular/core/primitives/signals';


/**
Expand Down Expand Up @@ -211,7 +212,15 @@ export class NbDialogService {
dialogRef.componentRef = container.attachComponentPortal(portal);

if (config.context) {
Object.assign(dialogRef.componentRef.instance, { ...config.context })
for (const [key, value] of Object.entries({...config.context})) {
const instance = dialogRef.componentRef.instance;
const member = instance[key];
if (typeof member === 'function' && member[SIGNAL] !== undefined) {
instance[key] = signal(value).asReadonly();
} else {
instance[key] = value;
}
}
}
}
}
Expand Down