You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何强制关闭NG-ZORRO的NzNotificationService通知弹窗?

解决NG-ZORRO Notification强制关闭的问题

你可以直接调用create方法返回对象的close()方法来强制关闭目标通知,调整后的代码示例如下:

// 可选:导入类型以获得更好的类型提示
import { NzNotificationRef } from 'ng-zorro-antd/notification';

private notif?: NzNotificationRef;

// 创建通知并保存返回的实例
this.notif = this.notification.create(
  'success',
  'Notification',
  'test message'
);

// 在需要强制关闭的操作时机执行以下代码
if (this.notif) {
  this.notif.close();
}

如果需要一次性关闭所有已弹出的通知,可以使用组件的remove()方法:

this.notification.remove();

说明:create方法返回的NzNotificationRef实例仅对应当前创建的这条通知,调用其close()只会关闭该条通知;而remove()方法会清除所有正在显示的通知。

内容的提问来源于stack exchange,提问作者Dickens A S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 21:30:55