Skip to content

Commit 992822e

Browse files
committed
perf(progress-circle): clean up animation on destroy
The indeterminate animation is based on an interval that keeps running, even after the element has been destroyed. This change cleans up when the element is destroyed.
1 parent b24d321 commit 992822e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/components/progress-circle/progress-circle.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ describe('MdProgressCircular', () => {
7474
done();
7575
});
7676
});
77+
78+
it('should clean up the indeterminate animation when the element is destroyed', (done: () => void) => {
79+
builder
80+
.overrideTemplate(TestApp, '<md-progress-circle mode="indeterminate" *ngIf="!isHidden"></md-progress-circle>')
81+
.createAsync(TestApp)
82+
.then((fixture) => {
83+
fixture.detectChanges();
84+
let progressElement = getChildDebugElement(fixture.debugElement, 'md-progress-circle');
85+
expect(progressElement.componentInstance._interdeterminateInterval).toBeTruthy();
86+
87+
fixture.debugElement.componentInstance.isHidden = true;
88+
fixture.detectChanges();
89+
expect(progressElement.componentInstance._interdeterminateInterval).toBeFalsy();
90+
done();
91+
});
92+
});
7793
});
7894

7995

src/components/progress-circle/progress-circle.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
HostBinding,
44
ChangeDetectorRef,
55
ChangeDetectionStrategy,
6+
OnDestroy,
67
Input
78
} from '@angular/core';
89

@@ -41,7 +42,7 @@ type EasingFn = (currentTime: number, startValue: number,
4142
styleUrls: ['progress-circle.css'],
4243
changeDetection: ChangeDetectionStrategy.OnPush,
4344
})
44-
export class MdProgressCircle {
45+
export class MdProgressCircle implements OnDestroy {
4546
/** The id of the last requested animation. */
4647
private _lastAnimationId: number = 0;
4748

@@ -60,6 +61,11 @@ export class MdProgressCircle {
6061
this._changeDetectorRef.markForCheck();
6162
}
6263

64+
/** Clean up any animations that were running. */
65+
ngOnDestroy() {
66+
this._cleanupIndeterminateAnimation();
67+
}
68+
6369
/**
6470
* Value of the progress circle.
6571
*

0 commit comments

Comments
 (0)