diff --git a/material.angular.io/src/app/pages/component-sidenav/component-nav.html b/material.angular.io/src/app/pages/component-sidenav/component-nav.html index 5a4e91705295..35b719409e83 100644 --- a/material.angular.io/src/app/pages/component-sidenav/component-nav.html +++ b/material.angular.io/src/app/pages/component-sidenav/component-nav.html @@ -1,12 +1,13 @@
@let items = (this.items | async) || []; + @let params = this._params | async; @if (items.length > 0) {
@for (component of items; track component) { diff --git a/material.angular.io/src/app/pages/component-sidenav/component-sidenav.html b/material.angular.io/src/app/pages/component-sidenav/component-sidenav.html index 0a5c46edeafd..c5cd6a896bee 100644 --- a/material.angular.io/src/app/pages/component-sidenav/component-sidenav.html +++ b/material.angular.io/src/app/pages/component-sidenav/component-sidenav.html @@ -6,7 +6,7 @@ [mode]="(isScreenSmall | async) ? 'over' : 'side'" [fixedInViewport]="(isScreenSmall | async)" [fixedTopGap]="(isExtraScreenSmall | async) ? 92 : 56"> - + }
@@ -15,7 +15,7 @@
@if ((isScreenSmall | async) === false) { - + }
diff --git a/material.angular.io/src/app/pages/component-sidenav/component-sidenav.ts b/material.angular.io/src/app/pages/component-sidenav/component-sidenav.ts index dc480bb3cda3..af6a7a218bb8 100644 --- a/material.angular.io/src/app/pages/component-sidenav/component-sidenav.ts +++ b/material.angular.io/src/app/pages/component-sidenav/component-sidenav.ts @@ -5,23 +5,14 @@ import { ViewEncapsulation, forwardRef, inject, - input, viewChild, } from '@angular/core'; -import {toObservable} from '@angular/core/rxjs-interop'; import {BreakpointObserver} from '@angular/cdk/layout'; import {AsyncPipe} from '@angular/common'; import {MatListItem, MatNavList} from '@angular/material/list'; import {MatSidenav, MatSidenavContainer} from '@angular/material/sidenav'; -import { - ActivatedRoute, - Params, - Routes, - RouterOutlet, - RouterLinkActive, - RouterLink, -} from '@angular/router'; -import {combineLatest, Observable, Subscription} from 'rxjs'; +import {ActivatedRoute, Routes, RouterOutlet, RouterLinkActive, RouterLink} from '@angular/router'; +import {Observable, of, Subscription} from 'rxjs'; import {map, switchMap} from 'rxjs/operators'; import {DocumentationItems} from '../../shared/documentation-items/documentation-items'; @@ -66,11 +57,9 @@ const SMALL_WIDTH_BREAKPOINT = 959; }) export class ComponentSidenav implements OnInit, OnDestroy { docItems = inject(DocumentationItems); - private _route = inject(ActivatedRoute); private _navigationFocusService = inject(NavigationFocusService); readonly sidenav = viewChild(MatSidenav); - params: Observable; isExtraScreenSmall: Observable; isScreenSmall: Observable; private _subscriptions = new Subscription(); @@ -84,11 +73,6 @@ export class ComponentSidenav implements OnInit, OnDestroy { this.isScreenSmall = breakpoints .observe(`(max-width: ${SMALL_WIDTH_BREAKPOINT}px)`) .pipe(map(breakpoint => breakpoint.matches)); - - this.params = combineLatest( - this._route.pathFromRoot.map(route => route.params), - Object.assign, - ); } ngOnInit() { @@ -120,12 +104,11 @@ export class ComponentSidenav implements OnInit, OnDestroy { }) export class ComponentNav { private _docItems = inject(DocumentationItems); - readonly params = input(); + private _route = inject(ActivatedRoute); + protected _params = this._route.params; - items = toObservable(this.params).pipe( - switchMap(params => - params?.section ? this._docItems.getItems(params.section) : Promise.resolve(null), - ), + items = this._params.pipe( + switchMap(params => (params?.section ? this._docItems.getItems(params.section) : of([]))), ); }