javascript - angularjs toastr 无法从粘性更改为动态关闭

标签 javascript angularjs angular-ui-bootstrap angular-ui

我正在使用( 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);
    };

updated

关于javascript - angularjs toastr 无法从粘性更改为动态关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40671774/

相关文章:

javascript - jQuery,附加 HTML 字符串不起作用

javascript - 使用 Facebook JavaScript SDK 时出现 SPDY 的 Chrom 错误

javascript - 如何在 AngularJs 中将对象转换为对象数组?

angularjs - 如何使用 AngularJS 对结果进行分页但在完整列表中进行过滤?

javascript - 如何纠正AngularJS中的分页

javascript - Adobe Acrobat Javascript setPageRotations 不旋转页面

Javascript 选项卡 - 如何在 URL 上添加主题标签?

javascript - 无法从angularjs ionic框架中的另一个 Controller 调用方法

angularjs - 使用 Angular-Wakanda 进行文件上传

angularjs - 修改 Accordion 使其表现得像 table 一样