fix(spinner): animation not being cleaned up when used with AoT (#1838)

Fixes #1283.
This commit is contained in:
Kristiyan Kostadinov
2016-11-15 03:01:35 +01:00
committed by Kara
parent a40cae9972
commit 83de14f827
2 changed files with 25 additions and 1 deletions
@@ -14,6 +14,7 @@ describe('MdProgressCircular', () => {
IndeterminateProgressSpinner,
ProgressSpinnerWithValueAndBoundMode,
IndeterminateProgressSpinnerWithNgIf,
SpinnerWithNgIf,
],
});
@@ -90,6 +91,20 @@ describe('MdProgressCircular', () => {
fixture.detectChanges();
expect(progressElement.componentInstance.interdeterminateInterval).toBeFalsy();
});
it('should clean up the animation when a spinner is destroyed', () => {
let fixture = TestBed.createComponent(SpinnerWithNgIf);
fixture.detectChanges();
let progressElement = fixture.debugElement.query(By.css('md-spinner'));
expect(progressElement.componentInstance.interdeterminateInterval).toBeTruthy();
fixture.debugElement.componentInstance.isHidden = true;
fixture.detectChanges();
expect(progressElement.componentInstance.interdeterminateInterval).toBeFalsy();
});
});
@@ -105,3 +120,6 @@ class ProgressSpinnerWithValueAndBoundMode { }
@Component({template: `
<md-progress-circle mode="indeterminate" *ngIf="!isHidden"></md-progress-circle>`})
class IndeterminateProgressSpinnerWithNgIf { }
@Component({template: `<md-spinner *ngIf="!isHidden"></md-spinner>`})
class SpinnerWithNgIf { }
+7 -1
View File
@@ -244,11 +244,17 @@ export class MdProgressCircle implements OnDestroy {
templateUrl: 'progress-circle.html',
styleUrls: ['progress-circle.css'],
})
export class MdSpinner extends MdProgressCircle {
export class MdSpinner extends MdProgressCircle implements OnDestroy {
constructor(changeDetectorRef: ChangeDetectorRef, elementRef: ElementRef, ngZone: NgZone) {
super(changeDetectorRef, ngZone, elementRef);
this.mode = 'indeterminate';
}
ngOnDestroy() {
// The `ngOnDestroy` from `MdProgressCircle` should be called explicitly, because
// in certain cases Angular won't call it (e.g. when using AoT and in unit tests).
super.ngOnDestroy();
}
}