Skip to content

Commit

Permalink
fix(spinner): animation not being cleaned up when used with AoT (#1838)
Browse files Browse the repository at this point in the history
Fixes #1283.
  • Loading branch information
crisbeto authored and kara committed Nov 15, 2016
1 parent a40cae9 commit 83de14f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/lib/progress-circle/progress-circle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('MdProgressCircular', () => {
IndeterminateProgressSpinner,
ProgressSpinnerWithValueAndBoundMode,
IndeterminateProgressSpinnerWithNgIf,
SpinnerWithNgIf,
],
});

Expand Down Expand Up @@ -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();
});
});


Expand All @@ -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 { }
8 changes: 7 additions & 1 deletion src/lib/progress-circle/progress-circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}


Expand Down

0 comments on commit 83de14f

Please sign in to comment.