Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mem-leak): Fix potential memory leaks. #15307

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
Output,
Renderer2,
booleanAttribute,
AfterContentInit
AfterContentInit,
OnDestroy
} from '@angular/core';
import { mkenum } from '../../core/utils';
import { IBaseEventArgs } from '../../core/utils';
Expand Down Expand Up @@ -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 | '';

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Loading