File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,9 @@ import {
10
10
Directive ,
11
11
Output ,
12
12
Input ,
13
- EventEmitter
13
+ EventEmitter ,
14
+ AfterContentInit ,
15
+ OnDestroy ,
14
16
} from '@angular/core' ;
15
17
16
18
import { Direction , Directionality } from './directionality' ;
@@ -27,7 +29,7 @@ import {Direction, Directionality} from './directionality';
27
29
host : { '[dir]' : 'dir' } ,
28
30
exportAs : 'dir' ,
29
31
} )
30
- export class Dir implements Directionality {
32
+ export class Dir implements Directionality , AfterContentInit , OnDestroy {
31
33
_dir : Direction = 'ltr' ;
32
34
33
35
/** Whether the `value` has been set to its initial value. */
@@ -40,7 +42,7 @@ export class Dir implements Directionality {
40
42
@Input ( 'dir' )
41
43
get dir ( ) : Direction { return this . _dir ; }
42
44
set dir ( v : Direction ) {
43
- let old = this . _dir ;
45
+ const old = this . _dir ;
44
46
this . _dir = v ;
45
47
if ( old !== this . _dir && this . _isInitialized ) {
46
48
this . change . emit ( this . _dir ) ;
@@ -54,5 +56,9 @@ export class Dir implements Directionality {
54
56
ngAfterContentInit ( ) {
55
57
this . _isInitialized = true ;
56
58
}
59
+
60
+ ngOnDestroy ( ) {
61
+ this . change . complete ( ) ;
62
+ }
57
63
}
58
64
Original file line number Diff line number Diff line change @@ -77,6 +77,19 @@ describe('Directionality', () => {
77
77
expect ( injectedDirectionality . value ) . toBe ( 'ltr' ) ;
78
78
expect ( fixture . componentInstance . changeCount ) . toBe ( 1 ) ;
79
79
} ) ) ;
80
+
81
+ it ( 'should complete the change stream on destroy' , fakeAsync ( ( ) => {
82
+ const fixture = TestBed . createComponent ( ElementWithDir ) ;
83
+ const dir =
84
+ fixture . debugElement . query ( By . directive ( InjectsDirectionality ) ) . componentInstance . dir ;
85
+ const spy = jasmine . createSpy ( 'complete spy' ) ;
86
+ const subscription = dir . change . subscribe ( undefined , undefined , spy ) ;
87
+
88
+ fixture . destroy ( ) ;
89
+ expect ( spy ) . toHaveBeenCalled ( ) ;
90
+ subscription . unsubscribe ( ) ;
91
+ } ) ) ;
92
+
80
93
} ) ;
81
94
} ) ;
82
95
You can’t perform that action at this time.
0 commit comments