Reputation: 1369
Hi I am using Angular Toastr (https://github.com/Foxandxss/angular-toastr) to create some messages on screen. 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. Also, I saw that there is a flag isOpened to check whether a particular message is opened or not.
Can someone tell me how I can use these callbacks to perform a particular action once any of these toastr messages is closed? This is the first time I am using them and am struggling a bit.
Upvotes: 1
Views: 1490
Reputation: 14216
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. 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.
Upvotes: 1