File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ describe('MdProgressCircular', () => {
14
14
IndeterminateProgressSpinner ,
15
15
ProgressSpinnerWithValueAndBoundMode ,
16
16
IndeterminateProgressSpinnerWithNgIf ,
17
+ SpinnerWithNgIf ,
17
18
] ,
18
19
} ) ;
19
20
@@ -90,6 +91,20 @@ describe('MdProgressCircular', () => {
90
91
fixture . detectChanges ( ) ;
91
92
expect ( progressElement . componentInstance . interdeterminateInterval ) . toBeFalsy ( ) ;
92
93
} ) ;
94
+
95
+ it ( 'should clean up the animation when a spinner is destroyed' , ( ) => {
96
+ let fixture = TestBed . createComponent ( SpinnerWithNgIf ) ;
97
+ fixture . detectChanges ( ) ;
98
+
99
+ let progressElement = fixture . debugElement . query ( By . css ( 'md-spinner' ) ) ;
100
+
101
+ expect ( progressElement . componentInstance . interdeterminateInterval ) . toBeTruthy ( ) ;
102
+
103
+ fixture . debugElement . componentInstance . isHidden = true ;
104
+ fixture . detectChanges ( ) ;
105
+
106
+ expect ( progressElement . componentInstance . interdeterminateInterval ) . toBeFalsy ( ) ;
107
+ } ) ;
93
108
} ) ;
94
109
95
110
@@ -105,3 +120,6 @@ class ProgressSpinnerWithValueAndBoundMode { }
105
120
@Component ( { template : `
106
121
<md-progress-circle mode="indeterminate" *ngIf="!isHidden"></md-progress-circle>` } )
107
122
class IndeterminateProgressSpinnerWithNgIf { }
123
+
124
+ @Component ( { template : `<md-spinner *ngIf="!isHidden"></md-spinner>` } )
125
+ class SpinnerWithNgIf { }
Original file line number Diff line number Diff line change @@ -244,11 +244,17 @@ export class MdProgressCircle implements OnDestroy {
244
244
templateUrl : 'progress-circle.html' ,
245
245
styleUrls : [ 'progress-circle.css' ] ,
246
246
} )
247
- export class MdSpinner extends MdProgressCircle {
247
+ export class MdSpinner extends MdProgressCircle implements OnDestroy {
248
248
constructor ( changeDetectorRef : ChangeDetectorRef , elementRef : ElementRef , ngZone : NgZone ) {
249
249
super ( changeDetectorRef , ngZone , elementRef ) ;
250
250
this . mode = 'indeterminate' ;
251
251
}
252
+
253
+ ngOnDestroy ( ) {
254
+ // The `ngOnDestroy` from `MdProgressCircle` should be called explicitly, because
255
+ // in certain cases Angular won't call it (e.g. when using AoT and in unit tests).
256
+ super . ngOnDestroy ( ) ;
257
+ }
252
258
}
253
259
254
260
You can’t perform that action at this time.
0 commit comments