我一直在 ngx-toastr ngx-toastr 的实际站点上阅读此内容,以及 Stack Overflow 上的其他帖子,但无法为我的工作案例找到明确的解决方案。
我正在尝试更改 toastr
的位置对于特定的用例。例子;出错时,显示toastr
在顶端。
我有一个非常普通的设置。
在我的 app.module.ts
我有以下内容:
import { ToastrModule } from 'ngx-toastr';
在我的
app.module.ts
的导入中我有:imports: [
BrowserModule,
ToastrModule.forRoot({
timeOut: 3500,
positionClass: 'toast-bottom-center',
preventDuplicates: true,
}),
在我的组件中,我声明了
toastr
在我的constructor
:constructor(private toastr: ToastrService) {}
我使用
toastr
如下:this.toastr.error('There was an error loading the Asset List!', 'Asset Register');
根据我的设置,所有 toast 都显示在
'toast-bottom-center'
.如何修改此调用以在顶部显示 toast ? this.toastr.error('There was an error loading the Asset List!', 'Asset Register');
最佳答案
error 方法的第三个参数用于提供 toastr 消息的位置(除其他外)。
this.toastrService.error('There was an error loading the Asset List!', 'Asset Register');
this.toastrService.warning('Some warning message', 'some title', {
positionClass: 'toast-bottom-right'
});
关于javascript - 如何在 Angular 5 中使用 ngx-toastr 更改每个用例的特定 toast 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49357790/