@@ -111,30 +111,28 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
111111 template : LOADING_TPL ,
112112 appendTo : $ionicBody . get ( )
113113 } )
114- . then ( function ( loader ) {
115- var self = loader ;
116-
117- loader . show = function ( options ) {
114+ . then ( function ( self ) {
115+ self . show = function ( options ) {
118116 var templatePromise = options . templateUrl ?
119117 $ionicTemplateLoader . load ( options . templateUrl ) :
120118 //options.content: deprecated
121119 $q . when ( options . template || options . content || '' ) ;
122120
123121 self . scope = options . scope || self . scope ;
124122
125- if ( ! this . isShown ) {
123+ if ( ! self . isShown ) {
126124 //options.showBackdrop: deprecated
127- this . hasBackdrop = ! options . noBackdrop && options . showBackdrop !== false ;
128- if ( this . hasBackdrop ) {
125+ self . hasBackdrop = ! options . noBackdrop && options . showBackdrop !== false ;
126+ if ( self . hasBackdrop ) {
129127 $ionicBackdrop . retain ( ) ;
130128 $ionicBackdrop . getElement ( ) . addClass ( 'backdrop-loading' ) ;
131129 }
132130 }
133131
134132 if ( options . duration ) {
135- $timeout . cancel ( this . durationTimeout ) ;
136- this . durationTimeout = $timeout (
137- angular . bind ( this , this . hide ) ,
133+ $timeout . cancel ( self . durationTimeout ) ;
134+ self . durationTimeout = $timeout (
135+ angular . bind ( self , self . hide ) ,
138136 + options . duration
139137 ) ;
140138 }
@@ -165,13 +163,13 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
165163 }
166164 } ) ;
167165
168- this . isShown = true ;
166+ self . isShown = true ;
169167 } ;
170- loader . hide = function ( ) {
168+ self . hide = function ( ) {
171169
172170 deregisterBackAction ( ) ;
173- if ( this . isShown ) {
174- if ( this . hasBackdrop ) {
171+ if ( self . isShown ) {
172+ if ( self . hasBackdrop ) {
175173 $ionicBackdrop . release ( ) ;
176174 $ionicBackdrop . getElement ( ) . removeClass ( 'backdrop-loading' ) ;
177175 }
@@ -181,11 +179,11 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
181179 ! self . isShown && self . element . removeClass ( 'visible' ) ;
182180 } , 200 ) ;
183181 }
184- $timeout . cancel ( this . durationTimeout ) ;
185- this . isShown = false ;
182+ $timeout . cancel ( self . durationTimeout ) ;
183+ self . isShown = false ;
186184 } ;
187185
188- return loader ;
186+ return self ;
189187 } ) ;
190188 }
191189 return loaderInstance ;
@@ -195,14 +193,15 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop,
195193 options = extend ( { } , $ionicLoadingConfig || { } , options || { } ) ;
196194 var delay = options . delay || options . showDelay || 0 ;
197195
196+ deregisterStateListener ( ) ;
197+ if ( options . hideOnStateChange ) {
198+ deregisterStateListener = $rootScope . $on ( '$stateChangeSuccess' , hideLoader ) ;
199+ }
200+
198201 //If loading.show() was called previously, cancel it and show with our new options
199- loadingShowDelay && $timeout . cancel ( loadingShowDelay ) ;
202+ $timeout . cancel ( loadingShowDelay ) ;
200203 loadingShowDelay = $timeout ( noop , delay ) ;
201-
202204 loadingShowDelay . then ( getLoader ) . then ( function ( loader ) {
203- if ( options . hideOnStateChange ) {
204- deregisterStateListener = $rootScope . $on ( '$stateChangeSuccess' , hideLoader ) ;
205- }
206205 return loader . show ( options ) ;
207206 } ) ;
208207
0 commit comments