66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { Component , OnDestroy , OnInit , inject } from '@angular/core' ;
9+ import { Component , inject , signal } from '@angular/core' ;
1010import { ActivatedRoute , RouterLink } from '@angular/router' ;
1111import { MatRipple } from '@angular/material/core' ;
12- import { combineLatest , Subscription } from 'rxjs' ;
12+ import { combineLatest } from 'rxjs' ;
1313
1414import {
1515 DocItem ,
@@ -19,40 +19,42 @@ import {
1919import { NavigationFocus } from '../../shared/navigation-focus/navigation-focus' ;
2020
2121import { ComponentPageTitle } from '../page-title/page-title' ;
22+ import { map , switchMap } from 'rxjs/operators' ;
23+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
2224
2325@Component ( {
2426 selector : 'app-component-category-list' ,
2527 templateUrl : './component-category-list.html' ,
2628 styleUrls : [ './component-category-list.scss' ] ,
2729 imports : [ NavigationFocus , RouterLink , MatRipple ] ,
2830} )
29- export class ComponentCategoryList implements OnInit , OnDestroy {
31+ export class ComponentCategoryList {
3032 private readonly _docItems = inject ( DocumentationItems ) ;
3133 private readonly _componentPageTitle = inject ( ComponentPageTitle ) ;
3234 private readonly _route = inject ( ActivatedRoute ) ;
3335
34- items : DocItem [ ] = [ ] ;
35- section = '' ;
36- routeParamSubscription : Subscription = new Subscription ( ) ;
37- _categoryListSummary : string | undefined ;
38-
39- ngOnInit ( ) {
40- this . routeParamSubscription = combineLatest (
41- this . _route . pathFromRoot . map ( route => route . params ) ,
42- Object . assign ,
43- ) . subscribe ( async params => {
44- const sectionName = params [ 'section' ] ;
45- const section = SECTIONS [ sectionName ] ;
46- this . _componentPageTitle . title = section . name ;
47- this . _categoryListSummary = section . summary ;
48- this . section = sectionName ;
49- this . items = await this . _docItems . getItems ( sectionName ) ;
50- } ) ;
51- }
36+ readonly items = signal < DocItem [ ] > ( [ ] ) ;
37+ readonly section = signal < string > ( '' ) ;
38+ readonly _categoryListSummary = signal < string | undefined > ( undefined ) ;
39+
40+ constructor ( ) {
41+ combineLatest ( this . _route . pathFromRoot . map ( route => route . params ) )
42+ . pipe (
43+ map ( paramsArray => Object . assign ( { } , ...paramsArray ) ) ,
44+ switchMap ( params => {
45+ const sectionName = params [ 'section' ] ;
46+ const section = SECTIONS [ sectionName ] ;
47+
48+ this . _componentPageTitle . title = section . name ;
49+ this . _categoryListSummary . set ( section . summary ) ;
50+ this . section . set ( sectionName ) ;
5251
53- ngOnDestroy ( ) {
54- if ( this . routeParamSubscription ) {
55- this . routeParamSubscription . unsubscribe ( ) ;
56- }
52+ return this . _docItems . getItems ( sectionName ) ;
53+ } ) ,
54+ takeUntilDestroyed ( ) ,
55+ )
56+ . subscribe ( items => {
57+ this . items . set ( items ) ;
58+ } ) ;
5759 }
5860}
0 commit comments