Angular PrimeNG的默认吐司位置是在页面的右上角。但是,您可以通过设置全局配置或在使用时指定选项来更改吐司位置。在全局配置中,您可以使用toastrConfig对象来设置吐司的位置选项。例如,要将吐司位置更改为左上角,可以将以下代码添加到app.module.ts文件中:
import { ToastrModule } from 'ngx-toastr';
toastrConfig = {
positionClass: 'toast-top-left'
}
@NgModule({
imports: [
ToastrModule.forRoot({
positionClass: this.toastrConfig.positionClass
})
]
})
如果您要在使用时指定选项,请将选项作为第二个参数传递给ngx-toastr的success,error,warning或info方法。例如,在以下代码中,吐司的位置将在左上角显示:
import { Component } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
@Component({
selector: 'app',
template: ''
})
export class AppComponent {
constructor(private toastr: ToastrService) {}
showToast() {
this.toastr.success('Hello, World!', '', {
positionClass: 'toast-top-left'
});
}
}
免责声明:本文内容通过AI工具匹配关键字智能整合而成,仅供参考,火山引擎不对内容的真实、准确或完整作任何形式的承诺。如有任何问题或意见,您可以通过联系service@volcengine.com进行反馈,火山引擎收到您的反馈后将及时答复和处理。