【问题标题】:Angular Toastr CallbacksAngular Toastr 回调
【发布时间】:2016-04-21 12:46:18
【问题描述】:

您好,我正在使用 Angular Toastr (https://github.com/Foxandxss/angular-toastr) 在屏幕上创建一些消息。我最多有两条消息可以在任何一个时间点同时打开,一条是错误类型,另一条是警告类型。两条消息都是持久的,必须由用户关闭。

我打开消息的方式就像在说明中解释的那样:

app.controller('foo', function($scope, toastr) {
    toastr.error('This is your error message', 'Error');
    toastr.warning('This is your warning message', 'Error');
});

但是,我想知道其中一个何时被用户关闭以及是哪一个。我在文档中看到有可以使用的回调 onHidden 和 onShown 但是我不知道如何使用它们,因为文档中没有更多信息。另外,我看到有一个标志 isOpened 来检查是否打开了特定消息。

有人可以告诉我,一旦这些 toastr 消息中的任何一个关闭,我可以如何使用这些回调来执行特定操作吗?这是我第一次使用它们并且有点挣扎。

【问题讨论】:

    标签: javascript angularjs toastr angular-toastr


    【解决方案1】:

    文档告诉你它希望你在回调中使用的函数的签名,类似这样......

     app.config(function(toastrConfig) {
       angular.extend(toastrConfig, {
           onHidden: myHideFunction
       }
    }
    

    那么无论你决定把这个函数放在哪里,它都会像这样:

    function myHideFunction(closedWithClick, toast) {
    // closedWithClick = bool that shows if toast was closed with click
    // toast = the whole toast that was closed
    //Put what ever action you want to happen here.
    
    }     
    

    看起来您将根据第二个参数toast 确定哪个已关闭,正如我标记的那样。文档说传递的是整个隐藏的 toast,所以你应该能够检查每个的独特之处,也许是一个类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多