首页 > 解决方案 > 如何知道点击了哪个特定的 toastr?

问题描述

我已经通过 ngx-toaster 成功展示了 toast。通过我根据 id 和任务代码显示各种类型的通知的烤面包机。

我试图获得点击回调和动作回调,但没有找到任何回报。

onNotificationReceived(res) {
        let key;
            switch (key) {
                case 1:
                    showSuccessPopup(res.title,res.body);
                    break;

                default:
                    break;
            }
    }

showSuccessPopup(title,body) {
        this.toastr
            .success(title, body, { closeButton: true })
            .onTap.subscribe((action) => console.log(action))
    }

实际结果:显示吐司

预期:显示了哪个 id toast

标签: angulartoastr

解决方案


onNotificationReceived(res) {
        let key;
            switch (key) {
                case 1:
                    showSuccessPopup(res.title,res.body);
                    break;

                default:
                    break;
            }
    }

showSuccessPopup(title,body) {
        const toast = this.toastr
            .success(title, body, { closeButton: true });
        toast.onTap.subscribe((action) => console.log(toast.toastId));
    }

您可以toastId从实际的 ActiveToast 实例将 传递给您的回调。

不幸的是,没有一个回调将返回实际的 toast 对象本身!


推荐阅读