Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module:tabs): add nzCanDeactivate hook #4476

Merged
merged 8 commits into from
Jan 8, 2020
Merged
5 changes: 3 additions & 2 deletions components/tabs/demo/guard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { NzCanChangeFn } from 'ng-zorro-antd/tabs';
Copy link
Member

@wzhudev wzhudev Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 Type 的名称最好再细化一些,或许其他组件将来也会有这样的需求

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wendzhue 对 API 名有什么更好的建议吗?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hsuanxyz NzTabsCanChangeFn ? 反正组件 specific 就好了。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那 Input 名呢,要不和 router 对齐一下?比如 nzCanActivateTabs

Copy link
Member Author

@danranVm danranVm Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那就这样吧 ~ @Input() nzCanDeactivate: NzTabsCanDeactivateFn

import { NzModalService } from 'ng-zorro-antd/modal';
import { Observable } from 'rxjs';

Expand All @@ -15,7 +16,7 @@ export class NzDemoTabsGuardComponent {
tabs = [1, 2, 3, 4];
constructor(private modal: NzModalService) {}

canChange = (fromIndex: number, toIndex: number) => {
canChange: NzCanChangeFn = (fromIndex: number, toIndex: number) => {
switch (fromIndex) {
case 0:
return toIndex === 1;
Expand All @@ -31,7 +32,7 @@ export class NzDemoTabsGuardComponent {
private confirm(): Observable<boolean> {
return new Observable(observer => {
this.modal.confirm({
nzTitle: '确定离开当前标签?',
nzTitle: 'Are you sure you want to leave this tab?',
nzOnOk: () => {
observer.next(true);
observer.complete();
Expand Down