【问题标题】:Where could I put a ngx-toastr config file?我可以在哪里放置 ngx-toastr 配置文件?
【发布时间】:2020-08-11 15:47:41
【问题描述】:

我是 Angular 的新手,并开始从事一些现有项目。

它在 package.json 依赖项中有"ngx-toastr": "~10.0.2",我需要更改它的一些默认参数。

我目前拥有的:

this.toastr.success('Message');

单次通话的效果:

  this.toastr.success('Message', null, {
    timeOut: 1000,
    extendedTimeOut: 1
  });

我找不到任何解释如何更改默认值的地方。既不是这里,也不是我找到的教程。

这么明显没有人觉得有必要提及它吗?我错过了什么?

【问题讨论】:

  • 你可以通过在你的模块中为 .forRoot 传入一个对象来设置默认值。这里的例子:sebgroup.github.io/ngx-toastr
  • @MikeOne 就像一个魅力!为什么不让它成为一个答案?
  • 目前在我的手机上创建格式正确的答案有点困难????。没问题,如果对你有帮助,我很高兴。

标签: angular toastr


【解决方案1】:

正如 MikeOne 所指出的,Angular 模块配置位于 app.module.ts
这是他的链接中的代码示例,演示了如何做到这一点:

import { BrowserModule } from '@angular/platform-browser';
import { ToastContainerModule, ToastrModule } from 'ngx-toastr';
// [...]

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
// Default module configuration can be tweaked here //
    ToastrModule.forRoot({
      timeOut: 10,
      progressBar: true,
      positionClass: 'toast-bottom-right'
    }),
    ToastContainerModule
  ],
  providers: [],
  bootstrap: [ AppComponent ]
})
export class AppModule { }
// [...]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多