I used Angular-toaster and it seems awesome. Searching stack and not found that:
How can I store number of open toasts in toaster-container in my controller?
angular.module('main', ['toaster', 'ngAnimate'])
.controller('myController', function($scope, toaster) {
$scope.pop = function(){
toaster.pop('info', "title", "text");
};
$scope.toastCount = function(){
//solution goes here
}
});
in html:
<toaster-container></toaster-container>
The code above is somehow pseudo, so you should be familiar with Angular-toaster to answer this question. Many thanks for any help ;)
You can use Angularjs-toaster's onShowCallback
and onHideCallback
to get currently open toaster count like this:
app.controller('myController', function($scope, toaster, $window) {
$scope.count = 0
$scope.pop = function() {
toaster.pop({
type: 'success',
title: 'Success',
body: 'This will work !',
onHideCallback: function() {
$scope.count--;
},
onShowCallback: function() {
$scope.count++;
}
});
};
});
As you can see on onShowCallback
i have incremented count and on onHideCallback
i have decremented the count to get currently open toaster count.
Also here is a working example: https://plnkr.co/edit/5WPdpYZJXUX5316obPej?p=preview
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.