@@ -12,16 +12,17 @@ import {
1212 ChangeDetectorRef ,
1313 Component ,
1414 Directive ,
15- OnDestroy ,
1615 OnInit ,
1716 ViewEncapsulation ,
1817 viewChild ,
1918 viewChildren ,
2019 inject ,
20+ DestroyRef ,
2121} from '@angular/core' ;
22+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
2223import { ActivatedRoute , Router , RouterLinkActive , RouterLink , RouterOutlet } from '@angular/router' ;
23- import { combineLatest , Observable , ReplaySubject , Subject } from 'rxjs' ;
24- import { map , skip , switchMap , takeUntil } from 'rxjs/operators' ;
24+ import { combineLatest , Observable , ReplaySubject } from 'rxjs' ;
25+ import { map , skip , switchMap } from 'rxjs/operators' ;
2526import { DocItem , DocumentationItems } from '../../shared/documentation-items/documentation-items' ;
2627import { TableOfContents } from '../../shared/table-of-contents/table-of-contents' ;
2728
@@ -46,14 +47,14 @@ import {MatTabLink, MatTabNav, MatTabNavPanel} from '@angular/material/tabs';
4647 RouterOutlet ,
4748 ] ,
4849} )
49- export class ComponentViewer implements OnDestroy {
50+ export class ComponentViewer {
5051 private _router = inject ( Router ) ;
5152 componentPageTitle = inject ( ComponentPageTitle ) ;
5253 readonly docItems = inject ( DocumentationItems ) ;
54+ private readonly _destroyRef = inject ( DestroyRef ) ;
5355
5456 componentDocItem = new ReplaySubject < DocItem > ( 1 ) ;
5557 sections : Set < string > = new Set ( [ 'overview' , 'api' ] ) ;
56- private _destroyed = new Subject < void > ( ) ;
5758
5859 constructor ( ) {
5960 const route = inject ( ActivatedRoute ) ;
@@ -74,7 +75,7 @@ export class ComponentViewer implements OnDestroy {
7475 const doc = await docItems . getItemById ( id , section ) ;
7576 return { doc, section} ;
7677 } ) ,
77- takeUntil ( this . _destroyed ) ,
78+ takeUntilDestroyed ( this . _destroyRef ) ,
7879 )
7980 . subscribe ( ( { doc, section} ) => {
8081 if ( ! doc ) {
@@ -98,11 +99,6 @@ export class ComponentViewer implements OnDestroy {
9899 }
99100 } ) ;
100101 }
101-
102- ngOnDestroy ( ) : void {
103- this . _destroyed . next ( ) ;
104- this . _destroyed . complete ( ) ;
105- }
106102}
107103
108104/**
@@ -111,15 +107,15 @@ export class ComponentViewer implements OnDestroy {
111107 * the table of contents headers.
112108 */
113109@Directive ( )
114- export class ComponentBaseView implements OnInit , OnDestroy {
110+ export class ComponentBaseView implements OnInit {
115111 componentViewer = inject ( ComponentViewer ) ;
116112 private _changeDetectorRef = inject ( ChangeDetectorRef ) ;
113+ private readonly _destroyRef = inject ( DestroyRef ) ;
117114
118115 readonly tableOfContents = viewChild < TableOfContents > ( 'toc' ) ;
119116 readonly viewers = viewChildren ( DocViewer ) ;
120117
121118 showToc : Observable < boolean > ;
122- private _destroyed = new Subject < void > ( ) ;
123119
124120 constructor ( ) {
125121 const breakpointObserver = inject ( BreakpointObserver ) ;
@@ -133,14 +129,16 @@ export class ComponentBaseView implements OnInit, OnDestroy {
133129 }
134130
135131 ngOnInit ( ) {
136- this . componentViewer . componentDocItem . pipe ( takeUntil ( this . _destroyed ) ) . subscribe ( ( ) => {
137- const tableOfContents = this . tableOfContents ( ) ;
138- if ( tableOfContents ) {
139- tableOfContents . resetHeaders ( ) ;
140- }
141- } ) ;
132+ this . componentViewer . componentDocItem
133+ . pipe ( takeUntilDestroyed ( this . _destroyRef ) )
134+ . subscribe ( ( ) => {
135+ const tableOfContents = this . tableOfContents ( ) ;
136+ if ( tableOfContents ) {
137+ tableOfContents . resetHeaders ( ) ;
138+ }
139+ } ) ;
142140
143- this . showToc . pipe ( skip ( 1 ) , takeUntil ( this . _destroyed ) ) . subscribe ( ( ) => {
141+ this . showToc . pipe ( skip ( 1 ) , takeUntilDestroyed ( this . _destroyRef ) ) . subscribe ( ( ) => {
144142 if ( this . tableOfContents ( ) ) {
145143 this . viewers ( ) . forEach ( viewer => {
146144 viewer . contentRendered . emit ( viewer . _elementRef . nativeElement ) ;
@@ -149,11 +147,6 @@ export class ComponentBaseView implements OnInit, OnDestroy {
149147 } ) ;
150148 }
151149
152- ngOnDestroy ( ) {
153- this . _destroyed . next ( ) ;
154- this . _destroyed . complete ( ) ;
155- }
156-
157150 updateTableOfContents ( sectionName : string , docViewerContent : HTMLElement , sectionIndex = 0 ) {
158151 const tableOfContents = this . tableOfContents ( ) ;
159152 if ( tableOfContents ) {
0 commit comments