加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular toastr提示框

发布时间:2020-12-17 07:04:18 所属栏目:安全 来源:网络整理
导读:1. 安装ngx-toastr包 npm install ngx-toastr --save 2. package.json中引入toastr样式文件 "styles": ["./node_modules/ngx-toastr/toastr.css" ] 3. 根模块中导入Toastr模块 import {ToastrModule} from ‘ngx-toastr‘;imports: [ ToastrModule.forRoot()

1. 安装ngx-toastr包

npm install ngx-toastr --save

2. package.json中引入toastr样式文件

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

3. 根模块中导入Toastr模块

import {ToastrModule} from ‘ngx-toastr‘;

imports: [ ToastrModule.forRoot() ]

4. 组件中使用toastr提示框

import {ToastrService} from ‘ngx-toastr‘;



export class TestComponent {

    // 注入Toastr服务

   constructor(private _toastrService: ToastrService) { }

    // 使用

    prevPage() {

        this._toastrService.info(‘info提示‘,‘这已经是第一页了‘);
        this._toastrService.success(‘success提示‘,‘这已经是第一页了‘);
        this._toastrService.warning(‘warning提示‘,‘这已经是第一页了‘);
        this._toastrService.error(‘error提示‘,‘这已经是第一页了‘);

    }

}

可以对提示框进行配置

this._toastrService.warning(‘提示内容‘,‘提示标题!(可省略此参数)‘,{
       closeButton: false,debug: false,progressBar: true,positionClass: "toast-bottom-center",onclick: null,showDuration: "300",hideDuration: "1000",timeOut: "2000",extendedTimeOut: "1000",showEasing: "swing",hideEasing: "linear",showMethod: "fadeIn",hideMethod: "fadeOut"  
    }
  );

参数说明:

  • closeButton:false,是否显示关闭按钮(提示框右上角关闭按钮);
  • debug:false,是否为调试;
  • progressBar:false,是否显示进度条(设置关闭的超时时间进度条);
  • positionClass,消息框在页面显示的位置
toast-top-left  顶端左边
  toast-top-right    顶端右边
  toast-top-center  顶端中间
  toast-top-full-width 顶端,宽度铺满整个屏幕
  toast-botton-right  
  toast-bottom-left
  toast-bottom-center
  toast-bottom-full-width
  • onclick,点击消息框自定义事件
  • showDuration: “300”,显示动作时间
  • hideDuration: “1000”,隐藏动作时间
  • timeOut: “2000”,自动关闭超时时间
  • extendedTimeOut: “1000”
  • showEasing: “swing”,
  • hideEasing: “linear”,
  • showMethod: “fadeIn” 显示的方式,和jquery相同
  • hideMethod: “fadeOut” 隐藏的方式,和jquery相同

5. 浏览器访问:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读