Skip to content

Commit

Permalink
fix(expansion): prevent memory leak by calling parent ngOnDestroy (#8410
Browse files Browse the repository at this point in the history
)
  • Loading branch information
anthonn authored and jelbourn committed Nov 20, 2017
1 parent d6f287e commit f6bd9b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/expansion/expansion-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class MatExpansionPanel extends _MatExpansionPanelMixinBase
}

ngOnDestroy() {
super.ngOnDestroy();
this._inputChanges.complete();
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/lib/expansion/expansion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('MatExpansionPanel', () => {
],
declarations: [
PanelWithContent,
PanelWithContentInNgIf,
PanelWithCustomMargin
],
});
Expand Down Expand Up @@ -138,6 +139,16 @@ describe('MatExpansionPanel', () => {
expect(arrow.style.transform).toBe('rotate(180deg)', 'Expected 180 degree rotation.');
}));

it('make sure accordion item runs ngOnDestroy when expansion panel is destroyed', () => {
let fixture = TestBed.createComponent(PanelWithContentInNgIf);
fixture.detectChanges();
let destroyedOk = false;
fixture.componentInstance.panel.destroyed.subscribe(() => destroyedOk = true);
fixture.componentInstance.expansionShown = false;
fixture.detectChanges();
expect(destroyedOk).toBe(true);
});

describe('disabled state', () => {
let fixture: ComponentFixture<PanelWithContent>;
let panel: HTMLElement;
Expand Down Expand Up @@ -221,6 +232,18 @@ class PanelWithContent {
@ViewChild(MatExpansionPanel) panel: MatExpansionPanel;
}

@Component({
template: `
<div *ngIf="expansionShown">
<mat-expansion-panel>
<mat-expansion-panel-header>Panel Title</mat-expansion-panel-header>
</mat-expansion-panel>
</div>`
})
class PanelWithContentInNgIf {
expansionShown = true;
@ViewChild(MatExpansionPanel) panel: MatExpansionPanel;
}

@Component({
styles: [
Expand Down

0 comments on commit f6bd9b0

Please sign in to comment.