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

使用Toast时报错 #840

Open
NamesJerry opened this issue May 26, 2022 · 1 comment
Open

使用Toast时报错 #840

NamesJerry opened this issue May 26, 2022 · 1 comment

Comments

@NamesJerry
Copy link

Version

6.0.0

Environment

ng-zorro-antd-mobile版本6.0.0 , angular版本13.2.0,angular-cli版本13.2.6

Reproduction link

https://stackblitz.com/edit/ng-zorro-antd-mobile-start?file=src/app/app.component.ts

Steps to reproduce

点击动作出现Toast,关闭后控制台报错,后面再继续点就出不来,报错:core.mjs:6485 ERROR DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node

What is expected?

能正常使用

What is actually happening?

半成品一个

Other?

@amoycode
Copy link

可以继承ToastService,然后改写hide方法。。。

@Injectable({ providedIn: 'root' })
export class CustomToastService extends ToastService {
  myZone?: NgZone;
  constructor(_appRef: ApplicationRef, _cfr: ComponentFactoryResolver, _zone: NgZone) {
    super(_appRef, _cfr, _zone);
    this.myZone = _zone;
    ToastService.prototype.hide = () => {
      if (this.timeout) {
        clearTimeout(this.timeout);
      }
      if (this.compRef) {
        this.myZone!.run(() => {
          this.compRef.destroy();
          if (document.body.contains(this.insertElement)) {
            document.body.removeChild(this.insertElement);
          }
        });
      }
    };
  }
}

使用

export class YourComponent {
  constructor(private customToast: CustomToastService) {}

  show() {
    this.customToast.fail('This is a message'):
  } 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants