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 {
1010 Directive ,
1111 Output ,
1212 Input ,
13- EventEmitter
13+ EventEmitter ,
14+ AfterContentInit ,
15+ OnDestroy ,
1416} from '@angular/core' ;
1517
1618import { Direction , Directionality } from './directionality' ;
@@ -27,7 +29,7 @@ import {Direction, Directionality} from './directionality';
2729 host : { '[dir]' : 'dir' } ,
2830 exportAs : 'dir' ,
2931} )
30- export class Dir implements Directionality {
32+ export class Dir implements Directionality , AfterContentInit , OnDestroy {
3133 _dir : Direction = 'ltr' ;
3234
3335 /** Whether the `value` has been set to its initial value. */
@@ -40,7 +42,7 @@ export class Dir implements Directionality {
4042 @Input ( 'dir' )
4143 get dir ( ) : Direction { return this . _dir ; }
4244 set dir ( v : Direction ) {
43- let old = this . _dir ;
45+ const old = this . _dir ;
4446 this . _dir = v ;
4547 if ( old !== this . _dir && this . _isInitialized ) {
4648 this . change . emit ( this . _dir ) ;
@@ -54,5 +56,9 @@ export class Dir implements Directionality {
5456 ngAfterContentInit ( ) {
5557 this . _isInitialized = true ;
5658 }
59+
60+ ngOnDestroy ( ) {
61+ this . change . complete ( ) ;
62+ }
5763}
5864
Original file line number Diff line number Diff line change @@ -77,6 +77,19 @@ describe('Directionality', () => {
7777 expect ( injectedDirectionality . value ) . toBe ( 'ltr' ) ;
7878 expect ( fixture . componentInstance . changeCount ) . toBe ( 1 ) ;
7979 } ) ) ;
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+
8093 } ) ;
8194} ) ;
8295
You can’t perform that action at this time.
0 commit comments