Last active
April 5, 2017 21:14
-
-
Save ronaiza-cardoso/8737b32e68823e3f160631b9616b673a to your computer and use it in GitHub Desktop.
Service to focus all Loadings of your application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { LoadingController, Loading, AlertController } from 'ionic-angular'; | |
// Declare LoadingService as a provider in app.module.ts | |
// Inject LoadingService in your class: constructor(public Loading: LoadingService){} | |
// Use the this.Loading.showLoading(), this.Loading.loadingDismiss() or this.Loading.showError() methods wherever you want | |
@Injectable() | |
export class LoadingService { | |
loading: Loading; | |
constructor(private loadingCrtl: LoadingController, private alertCtrl: AlertController) {} | |
showLoading() { | |
this.loading = this.loadingCrtl.create({ | |
content: 'Carregando...' | |
}); | |
this.loading.present(); | |
} | |
loadingDismiss() { | |
this.loading.dismiss(); | |
} | |
showError(text){ | |
setTimeout(() => { | |
this.loading.dismiss(); | |
}); | |
let alert = this.alertCtrl.create({ | |
title: 'Falha', | |
subTitle: text, | |
buttons: ['OK'] | |
}); | |
alert.present(prompt); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment