【问题标题】:give a 'toastr' popup its own options为“toastr”弹出窗口提供自己的选项
【发布时间】:2016-09-23 21:06:37
【问题描述】:

我的应用程序中都有 toastr 弹出窗口。它们可能会或可能不会在我的应用中进行自定义配置。

我正在使用 Angular,虽然我不确定这实际上是 Angular-toastr。

我想让这个 toastr 有不同的选项(位置、粘性、关闭按钮)——甚至是同一页面上的其他 toastr。

有没有办法为单个烤面包机实例指定选项,以便其他人不会继承它的选项?

在我的应用程序中的任何地方,我都会调用

toastr.success("Go team!");

它使用任何已经设置的默认值。

在这里,我想要这样的东西:

var bigToast = new toastr;
bigToast.options = {
    "closeButton": true,
    "positionClass": "toast-top-full-width",
     "tapToDismiss": true
}
bigToast.success("Yah! REALLY go team!")

这样,只有 bigToast 会受到影响。 '当然它不是构造函数,所以它失败了。

我正在尝试这个:

toastr.options = {
    "closeButton": true,
    "positionClass": "toast-top-full-width",
    "tapToDismiss": true
}
toastr.success(":)");

即使这样也没有效果,所以我显然是错误地实施了它。我看到了:),但没有一个选项被选中。

据我所知,toastr 对象是空的。这个:

toastr.options.positionClass = "toast-top-center"

抛出错误:

TypeError: Cannot set property 'positionClass' of undefined

我显然是个笨蛋,因为这看起来很简单,几乎不需要任何工作示例。

这些配置表单显示您可以做什么,但现在如何您实际做到了。

https://foxandxss.github.io/angular-toastr/

http://codeseven.github.io/toastr/demo.html

【问题讨论】:

  • 技术说明:表单将不接受有效的 toastr 拼写。拒绝提交。必须用引号括起来:'toastr'.

标签: toastr


【解决方案1】:

您只需要包含选项作为第三个参数。

toastr.success(":)","",{
"closeButton": true,
"positionClass": "toast-top-full-width",
"tapToDismiss": true});

第二个参数是标题,如果您不想显示标题,请留空。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    • 2015-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多