Skip to content

Commit e0389fa

Browse files
committed
refactor(button): unsubscribe from animationFrameScheduler on destroy
1 parent a6b6c94 commit e0389fa

File tree

1 file changed

+10
-4
lines changed
  • projects/igniteui-angular/directives/src/directives/button

1 file changed

+10
-4
lines changed

projects/igniteui-angular/directives/src/directives/button/button-base.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import {
99
booleanAttribute,
1010
inject,
1111
AfterViewInit,
12+
OnDestroy
1213
} from '@angular/core';
1314
import { PlatformUtil } from 'igniteui-angular/core';
14-
import { animationFrameScheduler } from 'rxjs';
15+
import { animationFrameScheduler, Subscription } from 'rxjs';
1516

1617
export const IgxBaseButtonType = {
1718
Flat: 'flat',
@@ -21,10 +22,11 @@ export const IgxBaseButtonType = {
2122

2223

2324
@Directive()
24-
export abstract class IgxButtonBaseDirective implements AfterViewInit{
25+
export abstract class IgxButtonBaseDirective implements AfterViewInit, OnDestroy {
2526
private _platformUtil = inject(PlatformUtil);
2627
public element = inject(ElementRef);
27-
private _viewInit = false;
28+
private _viewInit = false;
29+
private _animationScheduler: Subscription;
2830

2931
/**
3032
* Emitted when the button is clicked.
@@ -110,12 +112,16 @@ export abstract class IgxButtonBaseDirective implements AfterViewInit{
110112
if (this._platformUtil.isBrowser && !this._viewInit) {
111113
this._viewInit = true;
112114

113-
animationFrameScheduler.schedule(() => {
115+
this._animationScheduler = animationFrameScheduler.schedule(() => {
114116
this.element.nativeElement.style.removeProperty('--_init-transition');
115117
});
116118
}
117119
}
118120

121+
public ngOnDestroy(): void {
122+
this._animationScheduler.unsubscribe();
123+
}
124+
119125
/**
120126
* @hidden
121127
* @internal

0 commit comments

Comments
 (0)