@@ -28,6 +28,7 @@ import {
2828 DECLARATION_COMPONENT_VIEW ,
2929 HEADER_OFFSET ,
3030 HYDRATION ,
31+ INJECTOR ,
3132 LView ,
3233 TVIEW ,
3334 TView ,
@@ -48,6 +49,8 @@ import {
4849 removeLViewFromLContainer ,
4950} from '../view/container' ;
5051import { declareNoDirectiveHostTemplate } from './template' ;
52+ import { removeFromAnimationQueue } from '../../animation/queue' ;
53+ import { allLeavingAnimations } from '../../animation/longest_animation' ;
5154
5255/**
5356 * Creates an LContainer for an ng-template representing a root node
@@ -419,10 +422,11 @@ class LiveCollectionLContainerImpl extends LiveCollection<
419422 index ,
420423 shouldAddViewToDom ( this . templateTNode , dehydratedView ) ,
421424 ) ;
425+ clearDetachFlag ( this . lContainer , index ) ;
422426 }
423- override detach ( index : number , skipLeaveAnimations ?: boolean ) : LView < RepeaterContext < unknown > > {
427+ override detach ( index : number ) : LView < RepeaterContext < unknown > > {
424428 this . needsIndexUpdate ||= index !== this . length - 1 ;
425- if ( skipLeaveAnimations ) setSkipLeaveAnimations ( this . lContainer , index ) ;
429+ setDetachFlag ( this . lContainer , index ) ;
426430 return detachExistingView < RepeaterContext < unknown > > ( this . lContainer , index ) ;
427431 }
428432 override create ( index : number , value : unknown ) : LView < RepeaterContext < unknown > > {
@@ -570,13 +574,35 @@ function getLContainer(lView: LView, index: number): LContainer {
570574 return lContainer ;
571575}
572576
573- function setSkipLeaveAnimations ( lContainer : LContainer , index : number ) : void {
577+ function clearDetachFlag ( lContainer : LContainer , index : number ) : void {
578+ if ( lContainer . length <= CONTAINER_HEADER_OFFSET ) return ;
579+
580+ const indexInContainer = CONTAINER_HEADER_OFFSET + index ;
581+ const viewToDetach = lContainer [ indexInContainer ] ;
582+ if (
583+ viewToDetach &&
584+ viewToDetach [ ANIMATIONS ] &&
585+ ( viewToDetach [ ANIMATIONS ] as AnimationLViewData ) . detachFnQueue &&
586+ ( viewToDetach [ ANIMATIONS ] as AnimationLViewData ) . detachFnQueue ! . length > 0
587+ ) {
588+ const animations = viewToDetach [ ANIMATIONS ] as AnimationLViewData ;
589+ if ( animations . detachFnQueue && animations . detachFnQueue . length > 0 ) {
590+ const injector = viewToDetach [ INJECTOR ] ;
591+ removeFromAnimationQueue ( injector , animations ) ;
592+ allLeavingAnimations . delete ( viewToDetach ) ;
593+ animations . detachFnQueue = undefined ;
594+ }
595+ }
596+ }
597+
598+ function setDetachFlag ( lContainer : LContainer , index : number ) : void {
574599 if ( lContainer . length <= CONTAINER_HEADER_OFFSET ) return ;
575600
576601 const indexInContainer = CONTAINER_HEADER_OFFSET + index ;
577602 const viewToDetach = lContainer [ indexInContainer ] ;
578603 if ( viewToDetach && viewToDetach [ ANIMATIONS ] ) {
579- ( viewToDetach [ ANIMATIONS ] as AnimationLViewData ) . skipLeaveAnimations = true ;
604+ const animations = viewToDetach [ ANIMATIONS ] as AnimationLViewData ;
605+ animations . detachFnQueue = [ ] ;
580606 }
581607}
582608
0 commit comments