Angular 5 toastr提示插件小结

本文介绍了ngx-toastr的通知组件的安装步骤与基本使用方法,包括如何配置样式、位置及显示时间等,并提供了示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ngx-toastr
Demo:

1.安装
npm install ngx-toastr --save
需要依赖@angular/animations
npm install @angular/animations --save
如果不想用这个依赖,可以参考(但是通常都会安装aimations的):
2.添加css样式:
在.angular-cli.json中添加
" styles " : [
" styles.scss " ,
" ../node_modules/ngx-toastr/toastr.css "
]
3.根模块注入:
import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; //需要
import { ToastrModule } from 'ngx-toastr';

...

imports: [
   ...
    BrowserAnimationsModule,
    ToastrModule.forRoot()
]
4.使用:
import { ToastrService } from 'ngx-toastr';

...

constructor( public toastr: ToastrService ) {}


showSuccess() {
    this . toastr . success ( ' Hello world! ' , ' Toastr fun! ' );
}

可以对toastr做一些配置,比如,显示的位置,显示时间,显示颜色等等
this.toastr.warning('Too high!', 'Warning!',
    {
      timeOut: 0,
      closeButton: false,
      positionClass: 'toast-top-center'
    }
  );
具体配置属性:
也可以查看开始的Demo地址。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值