1- import { ChangeDetectionStrategy , Component , OnInit , ViewEncapsulation } from '@angular/core' ;
1+ import { ChangeDetectionStrategy , Component , OnDestroy , OnInit , ViewEncapsulation } from '@angular/core' ;
22import { ActivatedRoute } from '@angular/router' ;
3- import { filter , map } from 'rxjs/operators' ;
3+ import { Subject } from 'rxjs' ;
4+ import { filter , map , takeUntil } from 'rxjs/operators' ;
45
56@Component ( {
67 changeDetection : ChangeDetectionStrategy . OnPush ,
@@ -9,18 +10,23 @@ import { filter, map } from 'rxjs/operators';
910 styleUrls : [ './docs-root.component.scss' ] ,
1011 templateUrl : './docs-root.component.html' ,
1112} )
12- export class DocsRootComponent implements OnInit {
13+ export class DocsRootComponent implements OnInit , OnDestroy {
14+ private readonly componentDestroyed$ = new Subject < boolean > ( ) ;
15+
1316 constructor ( private readonly route : ActivatedRoute ) { }
1417
1518 ngOnInit ( ) : void {
1619 this . route . params
1720 . pipe (
21+ takeUntil ( this . componentDestroyed$ ) ,
1822 map ( ( { id } ) => document . getElementById ( id ) ) ,
1923 filter ( element => ! ! element ) ,
2024 )
21- // FIXME: unsub.
22- . subscribe ( element => {
23- element . scrollIntoView ( ) ;
24- } ) ;
25+ . subscribe ( element => element . scrollIntoView ( ) ) ;
26+ }
27+
28+ ngOnDestroy ( ) : void {
29+ this . componentDestroyed$ . next ( true ) ;
30+ this . componentDestroyed$ . unsubscribe ( ) ;
2531 }
2632}
0 commit comments