gpt4 book ai didi

javascript - AngularJS-Toaster toastr 容器中的 toast 数量

转载 作者:行者123 更新时间:2023-12-03 03:36:49 25 4
gpt4 key购买 nike

我用了Angular-toaster看起来棒极了。搜索堆栈并没有发现:
如何在 Controller 的 toastr 容器中存储打开的 toast 数量?

angular.module('main', ['toaster', 'ngAnimate'])
.controller('myController', function($scope, toaster) {
$scope.pop = function(){
toaster.pop('info', "title", "text");
};
$scope.toastCount = function(){
//solution goes here
}
});

在 html 中:

<toaster-container></toaster-container>

上面的代码在某种程度上是伪代码,因此您应该熟悉 Angular-toaster 才能回答这个问题。非常感谢您的帮助;)

最佳答案

您可以使用 Angularjs-toaster 的 onShowCallbackonHideCallback 来获取当前打开的 toastr 数量,如下所示:

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++;
}
});
};
});

正如您在 onShowCallback 上看到的,我增加了计数,在 onHideCallback 上我减少了计数以获取当前打开的 toastr 计数。

这里还有一个工作示例: https://plnkr.co/edit/5WPdpYZJXUX5316obPej?p=preview

关于javascript - AngularJS-Toaster toastr 容器中的 toast 数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45818829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com