@@ -182,33 +182,39 @@ export function createHttpDirective(method, attrName) {
182182 *
183183 * @param {string | Object } html - The HTML string or object returned from the server.
184184 * @param {import("./interface.ts").SwapModeType } swap
185- * @param {ng.Scope } scope
186- * @param {ng.Attributes } attrs
187- * @param {Element } element
185+ * @param {ng.Scope } scopeParam
186+ * @param {ng.Attributes } attrsParam
187+ * @param {Element } elmenetParam
188188 */
189- function handleSwapResponse ( html , swap , scope , attrs , element ) {
189+ function handleSwapResponse (
190+ html ,
191+ swap ,
192+ scopeParam ,
193+ attrsParam ,
194+ elmenetParam ,
195+ ) {
190196 let animationEnabled = false ;
191197
192- if ( attrs . animate ) {
198+ if ( attrsParam . animate ) {
193199 animationEnabled = true ;
194200 }
195201 let nodes = [ ] ;
196202
197203 if ( ! [ "textcontent" , "delete" , "none" ] . includes ( swap ) ) {
198204 if ( ! html ) return ;
199- const compiled = $compile ( html ) ( scope ) ;
205+ const compiled = $compile ( html ) ( scopeParam ) ;
200206
201207 nodes =
202208 compiled instanceof DocumentFragment
203209 ? Array . from ( compiled . childNodes )
204210 : [ compiled ] ;
205211 }
206212
207- const targetSelector = attrs . target ;
213+ const targetSelector = attrsParam . target ;
208214
209215 const target = targetSelector
210216 ? document . querySelector ( targetSelector )
211- : element ;
217+ : elmenetParam ;
212218
213219 if ( ! target ) {
214220 $log . warn ( `${ attrName } : target "${ targetSelector } " not found` ) ;
@@ -256,10 +262,10 @@ export function createHttpDirective(method, attrName) {
256262 }
257263
258264 content = insertedNodes ;
259- scope . $flushQueue ( ) ; // flush once after all insertions
265+ scopeParam . $flushQueue ( ) ; // flush once after all insertions
260266 } ) ;
261267
262- scope . $flushQueue ( ) ; // flush leave animation
268+ scopeParam . $flushQueue ( ) ; // flush leave animation
263269 break ;
264270 }
265271
@@ -268,10 +274,10 @@ export function createHttpDirective(method, attrName) {
268274 $animate . leave ( target ) . done ( ( ) => {
269275 target . textContent = html ;
270276 $animate . enter ( target , target . parentNode ) ;
271- scope . $flushQueue ( ) ;
277+ scopeParam . $flushQueue ( ) ;
272278 } ) ;
273279
274- scope . $flushQueue ( ) ;
280+ scopeParam . $flushQueue ( ) ;
275281 } else {
276282 target . textContent = html ;
277283 }
@@ -290,7 +296,7 @@ export function createHttpDirective(method, attrName) {
290296 }
291297 } ) ;
292298
293- if ( animationEnabled ) scope . $flushQueue ( ) ;
299+ if ( animationEnabled ) scopeParam . $flushQueue ( ) ;
294300 break ;
295301 }
296302
@@ -305,7 +311,7 @@ export function createHttpDirective(method, attrName) {
305311 }
306312 } ) ;
307313
308- if ( animationEnabled ) scope . $flushQueue ( ) ;
314+ if ( animationEnabled ) scopeParam . $flushQueue ( ) ;
309315 break ;
310316 }
311317
@@ -318,7 +324,7 @@ export function createHttpDirective(method, attrName) {
318324 }
319325 } ) ;
320326
321- if ( animationEnabled ) scope . $flushQueue ( ) ;
327+ if ( animationEnabled ) scopeParam . $flushQueue ( ) ;
322328 break ;
323329 }
324330
@@ -336,17 +342,17 @@ export function createHttpDirective(method, attrName) {
336342 }
337343 } ) ;
338344
339- if ( animationEnabled ) scope . $flushQueue ( ) ;
345+ if ( animationEnabled ) scopeParam . $flushQueue ( ) ;
340346 break ;
341347 }
342348
343349 case "delete" :
344350 if ( animationEnabled ) {
345351 $animate . leave ( target ) . done ( ( ) => {
346352 target . remove ( ) ; // safety: actually remove in case $animate.leave didn't
347- scope . $flushQueue ( ) ;
353+ scopeParam . $flushQueue ( ) ;
348354 } ) ;
349- scope . $flushQueue ( ) ;
355+ scopeParam . $flushQueue ( ) ;
350356 } else {
351357 target . remove ( ) ;
352358 }
@@ -362,17 +368,17 @@ export function createHttpDirective(method, attrName) {
362368 $animate . leave ( content ) . done ( ( ) => {
363369 content = nodes [ 0 ] ;
364370 $animate . enter ( nodes [ 0 ] , target ) ;
365- scope . $flushQueue ( ) ;
371+ scopeParam . $flushQueue ( ) ;
366372 } ) ;
367- scope . $flushQueue ( ) ;
373+ scopeParam . $flushQueue ( ) ;
368374 } else {
369375 content = nodes [ 0 ] ;
370376
371377 if ( content . nodeType === Node . TEXT_NODE ) {
372378 target . replaceChildren ( ...nodes ) ;
373379 } else {
374380 $animate . enter ( nodes [ 0 ] , target ) ;
375- scope . $flushQueue ( ) ;
381+ scopeParam . $flushQueue ( ) ;
376382 }
377383 }
378384 } else {
@@ -407,15 +413,21 @@ export function createHttpDirective(method, attrName) {
407413
408414 const html = res . data ;
409415
410- if ( Http . OK <= res . status && res . status <= 299 ) {
416+ if (
417+ Http . OK <= res . status &&
418+ res . status <= Http . MultipleChoices - 1
419+ ) {
411420 if ( isDefined ( attrs . success ) ) {
412421 $parse ( attrs . success ) ( scope , { $res : html } ) ;
413422 }
414423
415424 if ( isDefined ( attrs . stateSuccess ) ) {
416425 $state . go ( attrs . stateSuccess ) ;
417426 }
418- } else if ( 400 <= res . status && res . status <= 599 ) {
427+ } else if (
428+ Http . BadRequest <= res . status &&
429+ res . status <= Http . ErrorMax
430+ ) {
419431 if ( isDefined ( attrs . error ) ) {
420432 $parse ( attrs . error ) ( scope , { $res : html } ) ;
421433 }
0 commit comments