diff --git a/projects/igniteui-angular/src/lib/directives/button/button.directive.ts b/projects/igniteui-angular/src/lib/directives/button/button.directive.ts index c8009a1cf59..e414134bfac 100644 --- a/projects/igniteui-angular/src/lib/directives/button/button.directive.ts +++ b/projects/igniteui-angular/src/lib/directives/button/button.directive.ts @@ -7,7 +7,8 @@ import { Output, Renderer2, booleanAttribute, - AfterContentInit + AfterContentInit, + OnDestroy } from '@angular/core'; import { mkenum } from '../../core/utils'; import { IBaseEventArgs } from '../../core/utils'; @@ -46,7 +47,7 @@ export type IgxButtonType = typeof IgxButtonType[keyof typeof IgxButtonType]; selector: '[igxButton]', standalone: true }) -export class IgxButtonDirective extends IgxButtonBaseDirective implements AfterContentInit { +export class IgxButtonDirective extends IgxButtonBaseDirective implements AfterContentInit, OnDestroy { private static ngAcceptInputType_type: IgxButtonType | ''; /** @@ -92,6 +93,12 @@ export class IgxButtonDirective extends IgxButtonBaseDirective implements AfterC */ private _selected = false; + private emitSelected() { + this.buttonSelected.emit({ + button: this + }); + } + /** * Gets or sets whether the button is selected. * Mainly used in the IgxButtonGroup component and it will have no effect if set separately. @@ -121,11 +128,11 @@ export class IgxButtonDirective extends IgxButtonBaseDirective implements AfterC } public ngAfterContentInit() { - this.nativeElement.addEventListener('click', () => { - this.buttonSelected.emit({ - button: this - }); - }); + this.nativeElement.addEventListener('click', this.emitSelected.bind(this)); + } + + public ngOnDestroy(): void { + this.nativeElement.removeEventListener('click', this.emitSelected); } /** diff --git a/projects/igniteui-angular/src/lib/input-group/input-group.component.ts b/projects/igniteui-angular/src/lib/input-group/input-group.component.ts index 6c248c8a504..07a90b22659 100644 --- a/projects/igniteui-angular/src/lib/input-group/input-group.component.ts +++ b/projects/igniteui-angular/src/lib/input-group/input-group.component.ts @@ -219,15 +219,13 @@ export class IgxInputGroupComponent implements IgxInputGroupBase, AfterViewInit private themeToken: ThemeToken ) { this._theme = this.themeToken.theme; - - const { unsubscribe } = this.themeToken.onChange((theme) => { + const themeChange = this.themeToken.onChange((theme) => { if (this._theme !== theme) { this._theme = theme; this.cdr.detectChanges(); } }); - - this._destroyRef.onDestroy(() => unsubscribe); + this._destroyRef.onDestroy(() => themeChange.unsubscribe()); } /** @hidden */