【问题标题】:ngx-toastr, Toast not showing in Angularngx-toastr,Toast 未在 Angular 中显示
【发布时间】:2019-02-24 13:21:47
【问题描述】:

我正在使用 Angular 开发一个 Web 应用程序,我想包含 ngx-toastr 以向用户发送通知,但它没有按预期工作。当我触发敬酒时,没有任何反应,我的代码在下面,请有人帮助我,请我做错了什么

export class AppComponent  {
  constructor(
    private toast: ToastrService,
  ) { }

  test() {
    this.toast.success("I'm a toast!", "Success!");
  }
}

https://stackblitz.com/edit/angular-wsfroy?file=src%2Fapp%2Fapp.component.ts

【问题讨论】:

  • 当我点击Make a toast 按钮时,我可以看到吐司。只是它会在一秒钟左右消失
  • 但我想用成功背景显示右下角
  • 请看我的回答

标签: angular toastr


【解决方案1】:

您错过了添加 toast 所需的 css。

像下面这样添加angular.json的样式数组

   "styles": [
              "src/styles.css",
              "node_modules/ngx-toastr/toastr.css"
            ],

在此处查看更新后的stackblitz

【讨论】:

  • 在 styles.css 中添加 @import '~ngx-toastr/toastr.css'; 对我有用。
【解决方案2】:

在你的styles.css中添加

@import "toastr";

【讨论】:

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