zoukankan      html  css  js  c++  java
  • angular6 使用信息提示框toast

    angular6 可以使用的toast插件有好多个,在目前来看ngx-toastr在过去一年时间的使用量和受欢迎程度可以说是一骑绝尘,如下图:

    我也就选择了ngx-toastr这个插件,使用步骤如下:

    1、安装ngx-toastr和它的依赖@angular/animations

    npm install ngx-toastr --save
    npm install @angular/animations --save

    2、在angular-cli.json中添加css样式

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

    3、在app.module中导入相关模块

    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { ToastrModule } from 'ngx-toastr';
    import { AppComponent } from './app.component'; @NgModule({ imports: [ BrowserAnimationsModule,
    ToastrModule.forRoot() ], bootstrap: [AppComponent], declarations: [AppComponent] }) class AppModule {}

    4、使用toast

    import { ToastrService } from 'ngx-toastr';
     
    @Component({...})
    export class YourComponent {
      constructor(private toastr: ToastrService) {}
     
      showSuccess() {
        this.toastr.success('Hello world!', 'Toastr fun!');
      }
    }

    可以设置toast的消失时间为3秒:

    this.toastr.success('Hello world!', 'Toastr fun!', {timeOut: 3000})

    对toast做一些其他的配置可参考:https://github.com/scttcper/ngx-toastr#options

  • 相关阅读:
    php去除数组中重复值,并返回结果!
    SignalR 2 入门
    SignalR支持的平台
    SignalR简介
    作业调度系统quartz.net
    Oracle安装心得
    maven的项目目录解析
    web.xml的<url-parttern>的匹配规则
    Web.xml中四种验证方式
    Web.xml
  • 原文地址:https://www.cnblogs.com/lucky-heng/p/11129462.html
Copyright © 2011-2022 走看看