我已经通过ngx-toaster成功展示了吐司。 通过我,我正在根据ID和任务代码向烤面包机显示各种通知。
我试图获取tap回调和action回调,但是没有找到任何回报。
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吐司
答案 0 :(得分:1)
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对象本身!
答案 1 :(得分:0)
this.toastr.success()
显示一个敬酒通知并返回一个ActiveToast
对象。然后您在该特定的烤面包机上致电onTap
。如果要访问订阅中的toastr对象,请将其保存在变量中:
const toastr = this.toastr.success(/* ... */);
toastr.onTap.subscribe(action => /* use toastr here */);
/* you can also use toastr here */
toastr
看起来像这样:
export interface ActiveToast {
/** Your Toast ID. Use this to close it individually */
toastId: number;
/** the message of your toast. Stored to prevent duplicates */
message: string;
/** a reference to the component see portal.ts */
portal: ComponentRef<any>;
/** a reference to your toast */
toastRef: ToastRef<any>;
/** triggered when toast is active */
onShown: Observable<any>;
/** triggered when toast is destroyed */
onHidden: Observable<any>;
/** triggered on toast click */
onTap: Observable<any>;
/** available for your use in custom toast */
onAction: Observable<any>;
}
查看文档:{{3}}