Skip to content

Commit baab16c

Browse files
authored
feat(module:modal): Remove nzComponentParams in v16 (#7930)
1 parent 3b6bdec commit baab16c

10 files changed

+9
-87
lines changed

components/modal/demo/service.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ title:
99

1010
Modal的service用法,示例中演示了用户自定义模板、自定义component、以及注入模态框实例的方法。
1111

12-
使用模版作为内容或页脚时的上下文为 ` { $implicit: nzData || nzComponentParams, modalRef: NzModalRef }`
12+
使用模版作为内容或页脚时的上下文为 ` { $implicit: nzData, modalRef: NzModalRef }`
1313

1414
## en-US
1515

1616
Usage of Modal's service, examples demonstrate user-defined templates, custom components, and methods for injecting modal instances.
1717

18-
The template context is ` { $implicit: nzData || nzComponentParams, modalRef: NzModalRef }` when the content or footer is templates.
18+
The template context is ` { $implicit: nzData, modalRef: NzModalRef }` when the content or footer is templates.

components/modal/demo/service.ts

-7
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ export class NzDemoModalServiceComponent {
7878
nzFooter: tplFooter,
7979
nzMaskClosable: false,
8080
nzClosable: false,
81-
nzComponentParams: {
82-
value: 'Template Context'
83-
},
8481
nzOnOk: () => console.log('Click ok')
8582
});
8683
}
@@ -98,10 +95,6 @@ export class NzDemoModalServiceComponent {
9895
nzTitle: 'Modal Title',
9996
nzContent: NzModalCustomComponent,
10097
nzViewContainerRef: this.viewContainerRef,
101-
nzComponentParams: {
102-
title: 'title in component',
103-
subtitle: 'component sub title,will be changed after 2 sec'
104-
},
10598
nzData: {
10699
favoriteLibrary: 'angular',
107100
favoriteFramework: 'angular'

components/modal/doc/index.en-US.md

-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ The dialog is currently divided into 2 modes, `normal mode` and `confirm box mod
5656
| `nzOnCancel` | Specify a function that will be called when a user clicks mask, close button on top right or Cancel button (If nzContent is Component, the Component instance will be put in as an argument). <i>Note: When created with `NzModalService.create`, this parameter should be passed into the type of function (callback function). This function returns a promise, which is automatically closed when the execution is complete or the promise ends (return `false` to prevent closing)</i> | EventEmitter | - |
5757
| `nzOnOk` | Specify a EventEmitter that will be emitted when a user clicks the OK button (If nzContent is Component, the Component instance will be put in as an argument). <i>Note: When created with `NzModalService.create`, this parameter should be passed into the type of function (callback function). This function returns a promise, which is automatically closed when the execution is complete or the promise ends (return `false` to prevent closing)</i> | EventEmitter | - |
5858
| `nzContent` | Content | string / TemplateRef / Component / ng-content | - |
59-
| `nzComponentParams` | Deprecated, will be removed to the next major version, prefer using nzData. Will be instance property when `nzContent` is a component,will be template variable when `nzContent` is `TemplateRef` | `object` | - |
6059
| `nzData` | Will be a template variable when `nzContent` is `TemplateRef` | `object`, will be the value of the injection token NZ_MODAL_DATA when `nzContent` is a component| - |
6160
| `nzIconType` | Icon type of the Icon component. <i>Only valid in confirm box mode</i> | `string` | question-circle |
6261
| `nzAutofocus` | autofocus and the position,disabled when is `null` | `'ok' \| 'cancel' \| 'auto' \| null` | `'auto'` |
@@ -66,10 +65,6 @@ The dialog is currently divided into 2 modes, `normal mode` and `confirm box mod
6665
> NZ_MODAL_DATA injection token is used to retrieve `nzData` in the custom component.
6766
The dialog created by the service method `NzModalService.create()` inject a `NZ_MODAL_DATA` token (if `nzContent` is used as Component) to retrieve the parameters that have used to the '`nzContent` component'
6867

69-
#### Attentions
70-
71-
> The creation or modification of the `nzComponentParams` property does not trigger the `ngOnChanges` life cycle hook of the `nzContent` component.
72-
7368
#### Using service to create Normal Mode modal
7469

7570
> You can call `NzModalService.create(options)` to dynamically create **normal mode** modals, where `options` is an object that supports the support given in the API above **normal mode** parameters

components/modal/doc/index.zh-CN.md

-5
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,10 @@ import { NzModalModule } from 'ng-zorro-antd/modal';
6161
| nzOnCancel | 点击遮罩层或右上角叉或取消按钮的回调(若nzContent为Component,则将会以该Component实例作为参数)。<i>注:当以`NzModalService.create`创建时,此参数应传入function(回调函数)。该函数可返回promise,待执行完毕或promise结束时,将自动关闭对话框(返回false可阻止关闭)</i> | EventEmitter | - |
6262
| nzOnOk | 点击确定回调(若nzContent为Component,则将会以该Component实例作为参数)。<i>注:当以`NzModalService.create`创建时,此参数应传入function(回调函数)。该函数可返回promise,待执行完毕或promise结束时,将自动关闭对话框(返回false可阻止关闭)</i> | EventEmitter | - |
6363
| nzContent | 内容 | string<br>TemplateRef<br>Component<br>ng-content | - |
64-
| nzComponentParams |`nzContent` 为组件时将作为实例属性,为 `TemplateRef` 时将作为模版变量 | `object` | - |
6564
| nzIconType | 图标 Icon 类型。<i>仅 确认框模式 下有效</i> | `string` | `'question-circle'` |
6665
| nzAutofocus | 自动聚焦及聚焦位置,为 `null` 时禁用 | `'ok' \| 'cancel' \| 'auto' \| null` | `'auto'` |
6766

6867

69-
#### 注意
70-
71-
> `nzComponentParams` 属性的创建或修改不会触发 `nzContent` 组件的 `ngOnChanges` 生命周期钩子。
72-
7368
#### 采用服务方式创建普通模式对话框
7469

7570
> 您可调用 `NzModalService.create(options)` 来动态创建**普通模式**对话框,这里的 `options` 是一个对象,支持上方API中给出的支持 **普通模式** 的参数

components/modal/modal-footer.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ModalButtonOptions, ModalOptions } from './modal-types';
1919
template: `
2020
<ng-container *ngIf="config.nzFooter; else defaultFooterButtons">
2121
<ng-container
22-
*nzStringTemplateOutlet="config.nzFooter; context: { $implicit: config.nzComponentParams, modalRef: modalRef }"
22+
*nzStringTemplateOutlet="config.nzFooter; context: { $implicit: config.nzData, modalRef: modalRef }"
2323
>
2424
<div *ngIf="!buttonsFooter" [innerHTML]="config.nzFooter"></div>
2525
<ng-container *ngIf="buttonsFooter">

components/modal/modal-types.ts

-6
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ export class ModalOptions<T = NzSafeAny, D = NzSafeAny, R = NzSafeAny> {
4141
nzModalType?: ModalTypes = 'default';
4242
nzOnCancel?: EventEmitter<T> | OnClickCallback<T> = noopFun;
4343
nzOnOk?: EventEmitter<T> | OnClickCallback<T> = noopFun;
44-
45-
/**@deprecated
46-
* it's better to use nzData for the future, to respect naming convention from Angular team
47-
* must be remove for the nex major version
48-
*/
49-
nzComponentParams?: Partial<T>;
5044
nzData?: D;
5145
nzMaskStyle?: StyleObjectLike;
5246
nzBodyStyle?: StyleObjectLike;

components/modal/modal.component.ts

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export class NzModalComponent<T extends ModalOptions = NzSafeAny, R = NzSafeAny>
7070
@Input() @InputBoolean() nzNoAnimation = false;
7171
@Input() @InputBoolean() nzCentered = false;
7272
@Input() nzContent?: string | TemplateRef<{}> | Type<T>;
73-
@Input() nzComponentParams?: T;
7473
@Input() nzFooter?: string | TemplateRef<{}> | Array<ModalButtonOptions<T>> | null;
7574
@Input() nzZIndex: number = 1000;
7675
@Input() nzWidth: number | string = 520;

components/modal/modal.service.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { NzModalContainerComponent } from './modal-container.component';
2121
import { BaseModalContainerComponent } from './modal-container.directive';
2222
import { NzModalRef } from './modal-ref';
2323
import { ConfirmType, ModalOptions } from './modal-types';
24-
import { applyConfigDefaults, getValueWithConfig, setContentInstanceParams } from './utils';
24+
import { applyConfigDefaults, getValueWithConfig } from './utils';
2525

2626
type ContentType<T> = ComponentType<T> | TemplateRef<T> | string;
2727

@@ -179,7 +179,7 @@ export class NzModalService implements OnDestroy {
179179
if (componentOrTemplateRef instanceof TemplateRef) {
180180
modalContainer.attachTemplatePortal(
181181
new TemplatePortal<T>(componentOrTemplateRef, null!, {
182-
$implicit: config.nzData || config.nzComponentParams,
182+
$implicit: config.nzData,
183183
modalRef
184184
} as NzSafeAny)
185185
);
@@ -188,10 +188,6 @@ export class NzModalService implements OnDestroy {
188188
const contentRef = modalContainer.attachComponentPortal<T>(
189189
new ComponentPortal(componentOrTemplateRef, config.nzViewContainerRef, injector)
190190
);
191-
/**@deprecated
192-
* remove this method in the next major version now modal data are passed through injection
193-
*/
194-
setContentInstanceParams<T>(contentRef.instance, config.nzComponentParams);
195191
modalRef.componentInstance = contentRef.instance;
196192
} else {
197193
modalContainer.attachStringContent();

components/modal/modal.spec.ts

+4-42
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ describe('NzModal', () => {
124124
it('should open modal with component', () => {
125125
const modalRef = modalService.create({
126126
nzContent: TestWithModalContentComponent,
127-
nzComponentParams: {
128-
value: 'Modal'
129-
}
127+
nzData: 'Modal'
130128
});
131129

132130
fixture.detectChanges();
@@ -142,9 +140,6 @@ describe('NzModal', () => {
142140
it('should open a modal with data', () => {
143141
const modalRef = modalService.create({
144142
nzContent: TestWithModalContentComponent,
145-
nzComponentParams: {
146-
value: 'Modal'
147-
},
148143
nzData: 'NG-ZORRO'
149144
});
150145
fixture.detectChanges();
@@ -184,42 +179,10 @@ describe('NzModal', () => {
184179
expect(fixture.componentInstance.modalRef).toBe(modalRef);
185180
modalRef.close();
186181
});
187-
it('should open modal with template and pass value of Nz data even if nzComponentParams is set', () => {
188-
fixture.componentInstance.value = 'Modal';
189-
fixture.detectChanges();
190-
const modalRef = modalService.create({
191-
nzContent: fixture.componentInstance.templateRef,
192-
nzData: 'NG-ZORRO',
193-
nzComponentParams: 'Angular Material'
194-
});
195-
fixture.detectChanges();
196-
const modalContentElement = overlayContainerElement.querySelector('.modal-template-data');
197-
expect(modalContentElement).toBeTruthy();
198-
expect(modalContentElement!.textContent?.includes('NG-ZORRO')).toBeTruthy();
199-
expect(fixture.componentInstance.modalRef).toBe(modalRef);
200-
modalRef.close();
201-
});
202-
it('should open modal with template and pass value of nzComponentParams if nzData is not defined', () => {
203-
fixture.componentInstance.value = 'Modal';
204-
fixture.detectChanges();
205-
const modalRef = modalService.create({
206-
nzContent: fixture.componentInstance.templateRef,
207-
nzComponentParams: 'NG-ZORRO'
208-
});
209-
fixture.detectChanges();
210-
const modalContentElement = overlayContainerElement.querySelector('.modal-template-data');
211-
expect(modalContentElement).toBeTruthy();
212-
expect(modalContentElement!.textContent?.includes('NG-ZORRO')).toBeTruthy();
213-
expect(fixture.componentInstance.modalRef).toBe(modalRef);
214-
modalRef.close();
215-
});
216182

217183
it('should be thrown when attaching repeatedly', () => {
218184
const modalRefComponent = modalService.create({
219-
nzContent: TestWithModalContentComponent,
220-
nzComponentParams: {
221-
value: 'Modal'
222-
}
185+
nzContent: TestWithModalContentComponent
223186
});
224187

225188
expect(() => {
@@ -1483,9 +1446,7 @@ describe('NzModal', () => {
14831446
it('should open confirm with component', () => {
14841447
const modalRef = modalService.confirm({
14851448
nzContent: TestWithModalContentComponent,
1486-
nzComponentParams: {
1487-
value: 'Confirm'
1488-
}
1449+
nzData: 'Confirm'
14891450
});
14901451

14911452
fixture.detectChanges();
@@ -1778,6 +1739,7 @@ class TestWithModalContentComponent {
17781739
nzModalData: string;
17791740

17801741
constructor(public modalRef: NzModalRef, public modalInjector: Injector, @Inject(NZ_MODAL_DATA) nzData: string) {
1742+
this.value = nzData;
17811743
this.nzModalData = nzData;
17821744
}
17831745

components/modal/utils.ts

-12
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ export function getValueWithConfig<T>(
2121
: userValue;
2222
}
2323

24-
/**
25-
* Assign the params into the content component instance.
26-
*
27-
* @deprecated Should use dependency injection to get the params for user
28-
* @breaking-change 14.0.0
29-
*/
30-
export function setContentInstanceParams<T>(instance: T, params: Partial<T> | undefined): void {
31-
Object.assign(<{}>instance, params);
32-
}
33-
3424
export function getConfigFromComponent<T extends ModalOptions>(component: T): ModalOptions {
3525
const {
3626
nzCentered,
@@ -44,7 +34,6 @@ export function getConfigFromComponent<T extends ModalOptions>(component: T): Mo
4434
nzKeyboard,
4535
nzNoAnimation,
4636
nzContent,
47-
nzComponentParams,
4837
nzFooter,
4938
nzZIndex,
5039
nzWidth,
@@ -80,7 +69,6 @@ export function getConfigFromComponent<T extends ModalOptions>(component: T): Mo
8069
nzKeyboard,
8170
nzNoAnimation,
8271
nzContent,
83-
nzComponentParams,
8472
nzFooter,
8573
nzZIndex,
8674
nzWidth,

0 commit comments

Comments
 (0)