简体   繁体   English

Angular Toastr 回调

[英]Angular Toastr Callbacks

Hi I am using Angular Toastr ( https://github.com/Foxandxss/angular-toastr ) to create some messages on screen.嗨,我正在使用 Angular Toastr ( https://github.com/Foxandxss/angular-toastr ) 在屏幕上创建一些消息。 I have a maximum of two messages which can be open both at the same time at any one point in time, one which is of type error and another of type warning.我最多有两条消息可以在任何一个时间点同时打开,一条是错误类型,另一条是警告类型。 Both messages are persistent and have to be closed by the user.这两个消息都是持久的,必须由用户关闭。

The way I'm opening the messages is like how it's explained in the instructions:我打开消息的方式就像说明中的解释一样:

app.controller('foo', function($scope, toastr) {
    toastr.error('This is your error message', 'Error');
    toastr.warning('This is your warning message', 'Error');
});

However, I would like to know when one of these is closed by the user and which one it was.但是,我想知道用户何时关闭其中之一以及它是哪一个。 I saw on the documentation that there are callbacks onHidden and onShown which I can use however I am not aware how I can use these as there is no further info on the documentation.我在文档中看到有回调 onHidden 和 onShown 可以使用,但是我不知道如何使用这些,因为文档中没有更多信息。 Also, I saw that there is a flag isOpened to check whether a particular message is opened or not.另外,我看到有一个标志 isOpened 来检查是否打开了特定消息。

Can someone tell me how I can use these callbacks to perform a particular action once any of these toastr messages is closed?有人能告诉我一旦这些 toastr 消息中的任何一条关闭,我如何使用这些回调来执行特定操作吗? This is the first time I am using them and am struggling a bit.这是我第一次使用它们并且有点挣扎。

The docs tell you the signature of the function it wants you to use with the callback, something like this ...文档告诉您它希望您与回调一起使用的函数的签名,就像这样......

 app.config(function(toastrConfig) {
   angular.extend(toastrConfig, {
       onHidden: myHideFunction
   }
}

Then wherever you decide to put that function it would look like this :然后,无论您决定将该函数放在何处,它都将如下所示:

function myHideFunction(closedWithClick, toast) {
// closedWithClick = bool that shows if toast was closed with click
// toast = the whole toast that was closed
//Put what ever action you want to happen here.

}     

It looks like you would determine which one was closed based off that second param, toast as I have it labeled.它看起来像你将决定是基于关闭其中一个闭合时第二PARAM, toast ,因为我有它标记。 The docs say that what is being passed is the whole hidden toast, so you should be able to check something unique about each one, perhaps a class.文档说传递的是整个隐藏的吐司,所以你应该能够检查每个人的独特之处,也许是一个类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM