[英]AngularJS-Toaster number of toasts in toaster-container
I used Angular-toaster and it seems awesome. 我使用了Angular-toaster ,它看起来很棒。 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: 在html中:
<toaster-container></toaster-container>
The code above is somehow pseudo, so you should be familiar with Angular-toaster to answer this question. 上面的代码某种程度上是伪的,所以您应该熟悉Angular-toaster才能回答这个问题。 Many thanks for any help ;)
非常感谢您的帮助;)
You can use Angularjs-toaster's onShowCallback
and onHideCallback
to get currently open toaster count like this: 您可以使用Angularjs-toaster的
onShowCallback
和onHideCallback
来获取当前打开的烤面包机数量,如下所示:
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. 如您在
onShowCallback
看到的,我增加了计数,在onHideCallback
我减少了计数,以获取当前打开的烤面包机计数。
Also here is a working example: https://plnkr.co/edit/5WPdpYZJXUX5316obPej?p=preview 这也是一个工作示例: https : //plnkr.co/edit/5WPdpYZJXUX5316obPej?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.