我正在使用( Angularjs toaster ),我的要求是最初我需要使 toastr 具有粘性,并且在单击某些特定按钮后,应根据给定的时间间隔关闭所有 toastr 。因此,最初我将超时设置为 0,然后在 pop2() 函数中将超时设置为 2000。我可以清楚地看到 toasterOptions 对象中的超时更改为 2000,但所有 toastr 仍然很粘。
$scope.toasterOptions = {'time-out': 0, 'close-button':true, 'animation-class': 'toast-top-center'};
$scope.pop1 = function(){
toaster.success({title: "title1", body:"text1"});
};
$scope.pop2 = function(){
toaster.success({title: "title2", body:"text2"});
$scope.toasterOptions["time-out"] = 2000;
};
请参阅plunker
最佳答案
使用超时函数来调用清除函数,以便它会在给定的时间范围内清除所有内容,并且不要忘记在 Controller 中添加 $timeout
$scope.pop2 = function(){
toaster.success({title: "title2", body:"text2"});
$timeout(function() {
$scope.clear();
}, 2000);
};
关于javascript - angularjs toastr 无法从粘性更改为动态关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40671774/