angular - 如何知道点击了哪个特定的 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
解决方案
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 对象本身!
推荐阅读
- spring - 何时使用基于 Spring Security 的场景
- angular - 使用 Typescript + Angular 填充日期输入
- c++ - C++终端句柄按键在屏幕上运行
- tensorflow - 如何使用张量流将 [1,2,3,4,5,6] 重塑为 [[1,3,5],[2,4,6]]?
- dart - Flutter:实现 peek & pop 效果
- json - 将结构编组和解组到 json 会丢失信息
- javascript - WebPack 配置失败
- java - Hibernate 是否会检测到何时使用 id?
- matlab - Matlab & HDF5:写入的字符串属性具有 b'string' 格式
- vba - VBA Excel GetObject 问题 - 运行时错误 91 - 对象变量或未设置块变量