Skip to content

Commit 5168ba3

Browse files
authored
feat(theme:modalhelper): support signal of params (#1917)
1 parent 7619ca2 commit 5168ba3

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

packages/theme/src/services/modal/modal.helper.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DragDrop, DragRef } from '@angular/cdk/drag-drop';
22
import { DOCUMENT } from '@angular/common';
33
import { Injectable, TemplateRef, Type, inject } from '@angular/core';
4+
import { SIGNAL, SignalNode } from '@angular/core/primitives/signals';
45
import { Observable, Observer, delay, filter, take, tap } from 'rxjs';
56

67
import { deepMerge } from '@delon/util/other';
@@ -136,7 +137,15 @@ export class ModalHelper {
136137
} as ModalOptions);
137138
// 保留 nzComponentParams 原有风格,但依然可以通过 @Inject(NZ_MODAL_DATA) 获取
138139
if (subject.componentInstance != null && useNzData !== true) {
139-
Object.assign(subject.componentInstance, params);
140+
Object.entries(params as object).forEach(([key, value]) => {
141+
const t = subject.componentInstance as any;
142+
const s = t[key]?.[SIGNAL] as SignalNode<any>;
143+
if (s != null) {
144+
s.value = value;
145+
} else {
146+
t[key] = value;
147+
}
148+
});
140149
}
141150
subject.afterOpen
142151
.pipe(

packages/theme/src/services/modal/modal.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, inject } from '@angular/core';
1+
import { Component, inject, input } from '@angular/core';
22
import { ComponentFixture, fakeAsync, flush, TestBed, tick } from '@angular/core/testing';
33
import { provideNoopAnimations } from '@angular/platform-browser/animations';
44

@@ -47,6 +47,14 @@ describe('theme: ModalHelper', () => {
4747
expect(document.querySelector<HTMLElement>('.noNzData')?.innerText.trim()).toBe('true');
4848
expect(document.querySelector<HTMLElement>('.nzData')?.innerText.trim()).toBe('a');
4949
}));
50+
it('should be params allow signal', fakeAsync(() => {
51+
modal.create(TestModalComponent, { input_value: 10 }).subscribe(() => {
52+
expect(true).toBeTruthy();
53+
flush();
54+
});
55+
fixture.detectChanges();
56+
expect(document.querySelector<HTMLElement>('.input_value')?.innerText.trim()).toBe('10');
57+
}));
5058
describe('#exact width true', () => {
5159
it('should be not trigger subscript when return a undefined value', fakeAsync(() => {
5260
modal.create(TestModalComponent, { ret: undefined }, { includeTabs: true, exact: true }).subscribe({
@@ -160,11 +168,13 @@ describe('theme: ModalHelper', () => {
160168
template: `
161169
<div id="modal{{ id }}" class="handle noNzData">{{ ret }}</div>
162170
<div class="nzData">{{ data.ret }}</div>
171+
<div class="input_value">{{ input_value() }}</div>
163172
`
164173
})
165174
class TestModalComponent {
166175
id = '';
167176
ret = 'true';
177+
input_value = input<string>('');
168178

169179
private readonly modal = inject(NzModalRef);
170180
readonly data = inject<{ ret: string }>(NZ_MODAL_DATA, { optional: true });

src/app/shared/components/dialog/modal.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { JsonPipe } from '@angular/common';
2-
import { Component, Input, inject } from '@angular/core';
2+
import { Component, Input, inject, input, model } from '@angular/core';
33

44
import { NzButtonModule } from 'ng-zorro-antd/button';
55
import type { NzSafeAny } from 'ng-zorro-antd/core/types';
@@ -12,6 +12,8 @@ import { NzModalRef } from 'ng-zorro-antd/modal';
1212
<div class="modal-title">Custom component</div>
1313
</div>
1414
<p>参数:{{ record | json }}</p>
15+
<p>input_value: {{ input_value() }}</p>
16+
<p>model_value: {{ model_value() }}</p>
1517
<div class="modal-footer">
1618
<button nz-button [nzType]="'default'" [nzSize]="'large'" (click)="cancel()"> Cancel </button>
1719
<button nz-button [nzType]="'primary'" [nzSize]="'large'" (click)="ok()"> OK </button>
@@ -23,6 +25,8 @@ export class DemoModalComponent {
2325
private readonly modal = inject(NzModalRef);
2426

2527
@Input() record: NzSafeAny;
28+
input_value = input<string>('');
29+
model_value = model<string>('');
2630

2731
ok(): void {
2832
this.modal.destroy(`new time: ${+new Date()}`);

0 commit comments

Comments
 (0)