如何强制关闭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
相关产品推荐
相关产品推荐

