Skip to content

Commit cd67a82

Browse files
authored
test(module:modal): update to zoneless mode (#9608)
1 parent d59ec99 commit cd67a82

4 files changed

Lines changed: 666 additions & 942 deletions

File tree

components/modal/demo/async.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component, model, signal } from '@angular/core';
22

33
import { NzButtonModule } from 'ng-zorro-antd/button';
44
import { NzModalModule } from 'ng-zorro-antd/modal';
@@ -11,33 +11,33 @@ import { NzModalModule } from 'ng-zorro-antd/modal';
1111
<span>Show Modal</span>
1212
</button>
1313
<nz-modal
14-
[(nzVisible)]="isVisible"
14+
[(nzVisible)]="visible"
1515
nzTitle="Modal Title"
1616
(nzOnCancel)="handleCancel()"
1717
(nzOnOk)="handleOk()"
18-
[nzOkLoading]="isOkLoading"
18+
[nzOkLoading]="loading()"
1919
>
2020
<p *nzModalContent>Modal Content</p>
2121
</nz-modal>
2222
`
2323
})
2424
export class NzDemoModalAsyncComponent {
25-
isVisible = false;
26-
isOkLoading = false;
25+
visible = model(false);
26+
loading = signal(false);
2727

2828
showModal(): void {
29-
this.isVisible = true;
29+
this.visible.set(true);
3030
}
3131

3232
handleOk(): void {
33-
this.isOkLoading = true;
33+
this.loading.set(true);
3434
setTimeout(() => {
35-
this.isVisible = false;
36-
this.isOkLoading = false;
35+
this.visible.set(false);
36+
this.loading.set(false);
3737
}, 3000);
3838
}
3939

4040
handleCancel(): void {
41-
this.isVisible = false;
41+
this.visible.set(false);
4242
}
4343
}

components/modal/demo/service.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,28 +185,24 @@ export class NzDemoModalServiceComponent {
185185
selector: 'nz-modal-custom-component',
186186
imports: [NzButtonModule],
187187
template: `
188-
<div>
189-
<h2>{{ title }}</h2>
190-
<h4>{{ subtitle }}</h4>
191-
<p
192-
>My favorite framework is {{ nzModalData.favoriteFramework }} and my favorite library is
193-
{{ nzModalData.favoriteLibrary }}
194-
</p>
195-
<p>
196-
<span>Get Modal instance in component</span>
197-
<button nz-button [nzType]="'primary'" (click)="destroyModal()">destroy modal in the component</button>
198-
</p>
199-
</div>
188+
<h2>{{ title }}</h2>
189+
<h4>{{ subtitle }}</h4>
190+
<p>
191+
My favorite framework is {{ nzModalData.favoriteFramework }} and my favorite library is
192+
{{ nzModalData.favoriteLibrary }}
193+
</p>
194+
<br />
195+
<button nz-button (click)="destroyModal()">destroy modal in the component</button>
200196
`
201197
})
202198
export class NzModalCustomComponent {
203199
@Input() title?: string;
204200
@Input() subtitle?: string;
205201

206-
readonly #modal = inject(NzModalRef);
207-
readonly nzModalData: IModalData = inject(NZ_MODAL_DATA);
202+
readonly modalRef = inject(NzModalRef);
203+
readonly nzModalData = inject<IModalData>(NZ_MODAL_DATA);
208204

209205
destroyModal(): void {
210-
this.#modal.destroy({ data: 'this the result data' });
206+
this.modalRef.destroy({ data: 'this the result data' });
211207
}
212208
}

components/modal/modal-ref.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,13 @@ export class NzModalRef<T = NzSafeAny, R = NzSafeAny> implements NzModalLegacyAP
194194
const result = trigger(this.getContentComponent());
195195
if (isPromise(result)) {
196196
this.config[loadingKey] = true;
197+
this.updateConfig(this.config);
197198
let doClose: boolean | void | {} = false;
198199
try {
199200
doClose = (await result) as typeof result;
200201
} finally {
201202
this.config[loadingKey] = false;
203+
this.updateConfig(this.config);
202204
this.closeWhitResult(doClose);
203205
}
204206
} else {

0 commit comments

Comments
 (0)