Skip to content

Commit e75731a

Browse files
Merge pull request #15980 from IgniteUI/rivanova/fix-15976-20.0.x
fix(carousel-base): set animation players to null on destroy - 20.0.x
2 parents 9953ebd + b12933f commit e75731a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

projects/igniteui-angular/src/lib/carousel/carousel-base.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,14 @@ export abstract class IgxCarouselComponentBase implements OnDestroy {
5252
}
5353

5454
public ngOnDestroy(): void {
55-
this.enterAnimationPlayer?.destroy();
56-
this.leaveAnimationPlayer?.destroy();
55+
if (this.enterAnimationPlayer) {
56+
this.enterAnimationPlayer.destroy();
57+
this.enterAnimationPlayer = null;
58+
}
59+
if (this.leaveAnimationPlayer) {
60+
this.leaveAnimationPlayer.destroy();
61+
this.leaveAnimationPlayer = null;
62+
}
5763
}
5864

5965
/** @hidden */

projects/igniteui-angular/src/lib/carousel/carousel.component.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,17 @@ describe('Carousel', () => {
745745
expect(carousel.get(1).nativeElement.classList.contains(HelperTestFunctions.ACTIVE_SLIDE_CLASS)).toBeTruthy();
746746
expect(carousel.get(0).nativeElement.classList.contains(HelperTestFunctions.PREVIOUS_SLIDE_CLASS)).toBeFalsy();
747747
});
748+
749+
it('should not throw an error when playing an animation and destroying the component - #15976', () => {
750+
expect(() => {
751+
carousel.next();
752+
carousel.ngOnDestroy();
753+
fixture.detectChanges();
754+
}).not.toThrow();
755+
756+
expect(carousel['enterAnimationPlayer']).toBe(null);
757+
expect(carousel['leaveAnimationPlayer']).toBe(null);
758+
});
748759
});
749760

750761
describe('Dynamic Slides: ', () => {

0 commit comments

Comments
 (0)