11import { ContentSection } from '../models/content-section.model' ;
2- import { ChangeDetectorRef , Component , Injector , Input , OnDestroy } from '@angular/core' ;
3- import { ActivatedRoute , NavigationEnd , Router , NavigationExtras } from '@angular/router' ;
4- import { Subscription } from 'rxjs' ;
2+ import { ChangeDetectorRef , Component , Injector , Input } from '@angular/core' ;
3+ import { ActivatedRoute , Router , NavigationExtras } from '@angular/router' ;
54
65const availableTabsPaths = [ 'overview' , 'api' , 'examples' ] as const ;
76type AvailableTabsPathsType = typeof availableTabsPaths [ number ] ;
@@ -11,7 +10,7 @@ type AvailableTabsPathsType = typeof availableTabsPaths[number];
1110 selector : 'docs-section' ,
1211
1312 template : `
14- <ng-container *ngIf=" content">
13+ @if ( content) {
1514 <tabset class="example-tabset-box">
1615 <tab heading="Overview" [customClass]="'example-tabset'" [active]="overview" (selectTab)="onSelect('overview')">
1716 <ng-container *ngComponentOutlet="content[0].outlet; injector: sectionInjections(content[0])"></ng-container>
@@ -24,14 +23,13 @@ type AvailableTabsPathsType = typeof availableTabsPaths[number];
2423 </tab>
2524 </tabset>
2625 <add-nav class="add-nav" [componentContent]="overview ? content[0] : api ? content[1] : content[2]"></add-nav>
27- </ng-container>
26+ }
2827 ` ,
2928 standalone : false
3029} )
31- export class DocsSectionComponent implements OnDestroy {
30+ export class DocsSectionComponent {
3231 @Input ( ) content : ContentSection [ ] | undefined ;
3332 _injectors = new Map < ContentSection , Injector > ( ) ;
34- routeSubscription : Subscription ;
3533 overview = false ;
3634 api = false ;
3735 examples = false ;
@@ -42,11 +40,8 @@ export class DocsSectionComponent implements OnDestroy {
4240 private router : Router ,
4341 private changeDetection : ChangeDetectorRef
4442 ) {
45- this . routeSubscription = this . router . events . subscribe ( ( event ) => {
46- if ( event instanceof NavigationEnd ) {
47- const params = this . router . parseUrl ( event . url ) . queryParams ;
48- this . initActiveTab ( params [ 'tab' ] ?. toString ( ) ) ;
49- }
43+ this . activatedRoute . queryParamMap . subscribe ( ( params ) => {
44+ this . initActiveTab ( params . get ( 'tab' ) ?. toString ( ) ) ;
5045 } ) ;
5146 }
5247
@@ -59,7 +54,6 @@ export class DocsSectionComponent implements OnDestroy {
5954 }
6055
6156 this [ activeTab as AvailableTabsPathsType ] = true ;
62- this . changeDetection . detectChanges ( ) ;
6357 }
6458
6559 checkActiveTab ( activeTab : string ) : boolean {
@@ -99,8 +93,4 @@ export class DocsSectionComponent implements OnDestroy {
9993 this . api = false ;
10094 this . examples = false ;
10195 }
102-
103- ngOnDestroy ( ) {
104- this . routeSubscription . unsubscribe ( ) ;
105- }
10696}
0 commit comments