File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,20 @@ describe('MatOption component', () => {
13
13
} ) . compileComponents ( ) ;
14
14
} ) ) ;
15
15
16
+ it ( 'should complete the `stateChanges` stream on destroy' , ( ) => {
17
+ const fixture = TestBed . createComponent ( OptionWithDisable ) ;
18
+ fixture . detectChanges ( ) ;
19
+
20
+ const optionInstance : MatOption =
21
+ fixture . debugElement . query ( By . directive ( MatOption ) ) . componentInstance ;
22
+ const completeSpy = jasmine . createSpy ( 'complete spy' ) ;
23
+ const subscription = optionInstance . _stateChanges . subscribe ( undefined , undefined , completeSpy ) ;
24
+
25
+ fixture . destroy ( ) ;
26
+ expect ( completeSpy ) . toHaveBeenCalled ( ) ;
27
+ subscription . unsubscribe ( ) ;
28
+ } ) ;
29
+
16
30
describe ( 'ripples' , ( ) => {
17
31
let fixture : ComponentFixture < OptionWithDisable > ;
18
32
let optionDebugElement : DebugElement ;
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import {
23
23
InjectionToken ,
24
24
Inject ,
25
25
AfterViewChecked ,
26
+ OnDestroy ,
26
27
} from '@angular/core' ;
27
28
import { MatOptgroup } from './optgroup' ;
28
29
@@ -83,7 +84,7 @@ export const MAT_OPTION_PARENT_COMPONENT =
83
84
encapsulation : ViewEncapsulation . None ,
84
85
changeDetection : ChangeDetectionStrategy . OnPush ,
85
86
} )
86
- export class MatOption implements AfterViewChecked {
87
+ export class MatOption implements AfterViewChecked , OnDestroy {
87
88
private _selected = false ;
88
89
private _active = false ;
89
90
private _disabled = false ;
@@ -241,6 +242,10 @@ export class MatOption implements AfterViewChecked {
241
242
}
242
243
}
243
244
245
+ ngOnDestroy ( ) {
246
+ this . _stateChanges . complete ( ) ;
247
+ }
248
+
244
249
/** Emits the selection change event. */
245
250
private _emitSelectionChangeEvent ( isUserInput = false ) : void {
246
251
this . onSelectionChange . emit ( new MatOptionSelectionChange ( this , isUserInput ) ) ;
You can’t perform that action at this time.
0 commit comments