Skip to content

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

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

Merged
merged 1 commit into from
Nov 15, 2016
Merged
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
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();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tbosch Is this the intended behavior for generated code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to note that this happens in the unit tests as well. I'm pretty sure that they're not using AoT.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly yes, see angular/angular#11606

}


Expand Down