11import { MediaMatcher } from '@angular/cdk/layout' ;
2- import { ChangeDetectorRef , Component , OnDestroy } from '@angular/core' ;
2+ import { Component , OnDestroy , signal } from '@angular/core' ;
33import { MatListModule } from '@angular/material/list' ;
44import { MatSidenavModule } from '@angular/material/sidenav' ;
55import { MatIconModule } from '@angular/material/icon' ;
66import { MatButtonModule } from '@angular/material/button' ;
77import { MatToolbarModule } from '@angular/material/toolbar' ;
88import { NgIf , NgFor } from '@angular/common' ;
9+ import { RouterLink } from '@angular/router' ;
910
1011/** @title Responsive sidenav */
1112@Component ( {
@@ -21,14 +22,13 @@ import {NgIf, NgFor} from '@angular/common';
2122 MatSidenavModule ,
2223 MatListModule ,
2324 NgFor ,
25+ RouterLink ,
2426 ] ,
2527} )
2628export class SidenavResponsiveExample implements OnDestroy {
27- mobileQuery : MediaQueryList ;
29+ protected readonly fillerNav = Array . from ( { length : 50 } , ( _ , i ) => `Nav Item ${ i + 1 } ` ) ;
2830
29- fillerNav = Array . from ( { length : 50 } , ( _ , i ) => `Nav Item ${ i + 1 } ` ) ;
30-
31- fillerContent = Array . from (
31+ protected readonly fillerContent = Array . from (
3232 { length : 50 } ,
3333 ( ) =>
3434 `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
@@ -38,17 +38,23 @@ export class SidenavResponsiveExample implements OnDestroy {
3838 cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.` ,
3939 ) ;
4040
41- private _mobileQueryListener : ( ) => void ;
41+ protected readonly isMobile = signal ( true ) ;
42+
43+ private readonly _mobileQuery : MediaQueryList ;
44+ private readonly _mobileQueryListener : ( ) => void ;
4245
43- constructor ( changeDetectorRef : ChangeDetectorRef , media : MediaMatcher ) {
44- this . mobileQuery = media . matchMedia ( '(max-width: 600px)' ) ;
45- this . _mobileQueryListener = ( ) => changeDetectorRef . detectChanges ( ) ;
46- this . mobileQuery . addListener ( this . _mobileQueryListener ) ;
46+ constructor ( media : MediaMatcher ) {
47+ this . _mobileQuery = media . matchMedia ( '(max-width: 600px)' ) ;
48+ this . isMobile . set ( this . _mobileQuery . matches ) ;
49+ this . _mobileQueryListener = ( ) => this . isMobile . set ( this . _mobileQuery . matches ) ;
50+ this . _mobileQuery . addEventListener ( 'change' , this . _mobileQueryListener ) ;
4751 }
4852
4953 ngOnDestroy ( ) : void {
50- this . mobileQuery . removeListener ( this . _mobileQueryListener ) ;
54+ this . _mobileQuery . removeEventListener ( 'change' , this . _mobileQueryListener ) ;
5155 }
5256
53- shouldRun = / ( ^ | .) ( s t a c k b l i t z | w e b c o n t a i n e r ) .( i o | c o m ) $ / . test ( window . location . host ) ;
57+ protected readonly shouldRun = / ( ^ | .) ( s t a c k b l i t z | w e b c o n t a i n e r ) .( i o | c o m ) $ / . test (
58+ window . location . host ,
59+ ) ;
5460}
0 commit comments