1- import { Component , OnInit , OnDestroy } from '@angular/core' ;
2- import { Subject , takeUntil } from 'rxjs' ;
1+ import { Component , OnInit , computed } from '@angular/core' ;
32import { ThemeService } from './service/theme.service' ;
43import { TitleService } from './service/title.service' ;
54import { SidenavButtonsComponent } from './component/sidenav-buttons/sidenav-buttons.component' ;
@@ -28,14 +27,16 @@ import { MatToolbarModule } from '@angular/material/toolbar';
2827 RouterOutlet ,
2928 ] ,
3029} )
31- export class AppComponent implements OnInit , OnDestroy {
32- title = '' ;
30+ export class AppComponent implements OnInit {
3331 defaultTitle = '' ;
34- subtitle = '' ;
3532 menuIsOpen : boolean = true ;
3633 sidenavWidth : string = '250px' ;
3734
38- private destroy$ = new Subject < void > ( ) ;
35+ readonly title = computed ( ( ) => this . titleService . titleInfo ( ) ?. dimension || '' ) ;
36+ readonly subtitle = computed ( ( ) => {
37+ const info = this . titleService . titleInfo ( ) ;
38+ return info ?. level ? 'Level ' + info . level : '' ;
39+ } ) ;
3940
4041 constructor (
4142 private themeService : ThemeService ,
@@ -54,17 +55,6 @@ export class AppComponent implements OnInit, OnDestroy {
5455 } else {
5556 this . sidenavWidth = '250px' ;
5657 }
57-
58- // Subscribe to title changes
59- this . titleService . titleInfo$ . pipe ( takeUntil ( this . destroy$ ) ) . subscribe ( titleInfo => {
60- this . title = titleInfo ?. dimension || '' ;
61- this . subtitle = titleInfo ?. level ? 'Level ' + titleInfo ?. level : '' ;
62- } ) ;
63- }
64-
65- ngOnDestroy ( ) : void {
66- this . destroy$ . next ( ) ;
67- this . destroy$ . complete ( ) ;
6858 }
6959
7060 toggleMenu ( ) : void {
0 commit comments