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'
    });
  }
}

個(gè)人覺得,toastr也不是很美觀。。。。。。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容