11import { Injectable } from '@angular/core' ;
2- import { LoadingController } from 'ionic-angular' ;
3- import { PreRequestPlugin , PostRequestPlugin } from '@ramonornela/http' ;
2+ import { LoadingController , Loading } from 'ionic-angular' ;
3+ import { PreRequestPlugin , PostRequestPlugin , PostRequestErrorPlugin } from '@ramonornela/http' ;
44
55@Injectable ( )
6- export class LoadingIonicPlugin implements PreRequestPlugin , PostRequestPlugin {
6+ export class LoadingIonicPlugin implements PreRequestPlugin , PostRequestPlugin , PostRequestErrorPlugin {
77
8- protected loading ;
8+ protected loading : Loading = null ;
99
1010 protected allow : boolean = true ;
1111
@@ -32,8 +32,12 @@ export class LoadingIonicPlugin implements PreRequestPlugin, PostRequestPlugin {
3232 }
3333 }
3434
35- postRequest ( ) {
36- if ( this . allow && this . loading ) {
35+ dismiss ( ) {
36+ if ( this . loading === null ) {
37+ return ;
38+ }
39+
40+ if ( this . allow ) {
3741 this . loading . dismiss ( ) ;
3842 }
3943
@@ -48,6 +52,14 @@ export class LoadingIonicPlugin implements PreRequestPlugin, PostRequestPlugin {
4852 }
4953 }
5054
55+ postRequest ( ) {
56+ this . dismiss ( ) ;
57+ }
58+
59+ postRequestError ( ) {
60+ this . dismiss ( ) ;
61+ }
62+
5163 disableLoading ( restore : boolean = false ) : this {
5264 if ( restore === true ) {
5365 this . allowPrevious = this . allow ;
@@ -72,7 +84,7 @@ export class LoadingIonicPlugin implements PreRequestPlugin, PostRequestPlugin {
7284 }
7385
7486 protected getLoading ( ) {
75- if ( ! this . loading ) {
87+ if ( this . loading === null ) {
7688 this . loading = this . loadingController . create ( this . loadingOptions ) ;
7789 }
7890
0 commit comments