ionic4 集成ngx-toastr

GitHub:ngx-toastr 、演示地址:Demo
效果图:

3.png

4.png

5.png

6.png

Node安装依赖包(看下图,注意版本问题):
1.png

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

添加样式,在angular.json:


2.png

在app.module.ts:

import { CommonModule } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ToastrModule } from 'ngx-toastr';

@NgModule({
  imports: [
    CommonModule,
    BrowserAnimationsModule, // required animations module
    ToastrModule.forRoot() // ToastrModule added
  ],
  bootstrap: [App],
  declarations: [App]
})
class MainModule {}

ngx-toastr使用:

import { ToastrService } from 'ngx-toastr';

@Component({
  selector: 'app-test',
  templateUrl: './test.page.html',
  styleUrls: ['./test.page.scss']
})
export class TestComponent {
  constructor(private toastr: ToastrService) {}
  showToastr() {
    this.toastr.success('', '保存成功!',{
          timeOut:2000,
          positionClass:'toast-top-center'
    });
    this.toastr.info('', '信息!',{
          timeOut:2000,
          positionClass:'toast-top-center'
    });
    this.toastr.warning('', '警告!',{
          timeOut:2000,
          positionClass:'toast-top-center'
    });
    this.toastr.error('', '保存失败!',{
          timeOut:2000,
          positionClass:'toast-top-center'
    });
  }
}

个人觉得,toastr也不是很美观。。。。。。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容