【问题标题】:ngx-toastr ToastrService.show() type parameter Angular 2 +ngx-toastr ToastrService.show() 类型参数 Angular 2 +
【发布时间】:2018-10-29 17:18:38
【问题描述】:

我可以毫无问题地使用ToastrService.success/error/warning/info(),

但是当我使用ToastrService.show() 时,我不知道我应该发送哪种正确的字符串类型

我尝试发送这样的枚举:

export enum ToastType {
    Success = 'success',
    Error = 'error',
    Info = 'info',
    Warning = 'warning'
}

但组件会丢失样式。

【问题讨论】:

    标签: angular typescript angular-toastr ngtoast


    【解决方案1】:

    偶然发现同样的问题并在文档中找到了类型:

    iconClasses = {
      error: 'toast-error',
      info: 'toast-info',
      success: 'toast-success',
      warning: 'toast-warning'
    };
    

    来源: https://github.com/scttcper/ngx-toastr#iconclasses-defaults

    更新

    show() 方法有四个参数,其中类型是上面列出的名称。

    ToastrService.show(message?: string, title?: string, override?: Partial<IndividualConfig>, type?: string)
    

    可以在此处查看包含所有参数的示例: https://stackblitz.com/edit/angular-uu7r6s

    或者一个更完整的例子: https://github.com/grabowskidaniel/exemplo-ngx-toastr

    使用 NgxToastr 版本 10

    【讨论】:

      【解决方案2】:

      我是这样使用 ToasterService 的,

      this._toasterService.openToast("", "update success!", "success");
      
      this._toasterService.openToast("", "update error!", "error");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-06-02
        • 1970-01-01
        • 2019-05-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多