From 59cc3ed666d5ab94252d6fe517125bb347559733 Mon Sep 17 00:00:00 2001 From: Ratnadeep Rajendra Kharade <92khra1mst@hft-stuttgart.de> Date: Thu, 28 Nov 2019 15:38:02 +0100 Subject: [PATCH] Added service to show toast message. --- src/app/app.module.ts | 2 ++ src/app/services/toast.service.spec.ts | 12 ++++++++++++ src/app/services/toast.service.ts | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/app/services/toast.service.spec.ts create mode 100644 src/app/services/toast.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 238bde8..acf47d2 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -15,6 +15,7 @@ import { IonicStorageModule } from '@ionic/storage'; import { AppComponent } from './app.component'; import { AppRoutingModule } from './app-routing.module'; import { RestService } from './rest.service'; +import { ToastService } from './services/toast.service'; @NgModule({ declarations: [AppComponent], @@ -31,6 +32,7 @@ import { RestService } from './rest.service'; StatusBar, SplashScreen, RestService, + ToastService, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy } ], bootstrap: [AppComponent] diff --git a/src/app/services/toast.service.spec.ts b/src/app/services/toast.service.spec.ts new file mode 100644 index 0000000..2dc86dd --- /dev/null +++ b/src/app/services/toast.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { ToastService } from './toast.service'; + +describe('ToastService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: ToastService = TestBed.get(ToastService); + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/toast.service.ts b/src/app/services/toast.service.ts new file mode 100644 index 0000000..e892ad3 --- /dev/null +++ b/src/app/services/toast.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@angular/core'; +import { ToastController } from '@ionic/angular'; + +@Injectable({ + providedIn: 'root' +}) +export class ToastService { + + toast: any; + + constructor(public toastController: ToastController) { } + + showToast(message) { + this.toast = this.toastController.create({ + message: message, + duration: 2000 + }).then((toastData)=>{ + toastData.present(); + }); + } + HideToast(){ + this.toast = this.toastController.dismiss(); + } +} -- GitLab