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 { 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,46 +23,22 @@ 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 ;
3836
3937 constructor (
4038 private injector : Injector ,
41- private activatedRoute : ActivatedRoute ,
4239 private router : Router ,
4340 private changeDetection : ChangeDetectorRef
4441 ) {
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- }
50- } ) ;
51- }
52-
53- initActiveTab ( activeTab ?: string ) {
54- this . resetTabs ( ) ;
55- if ( ! activeTab || ! this . checkActiveTab ( activeTab ) ) {
56- this . overview = true ;
57- this . onSelect ( 'overview' ) ;
58- return ;
59- }
60-
61- this [ activeTab as AvailableTabsPathsType ] = true ;
62- this . changeDetection . detectChanges ( ) ;
63- }
64-
65- checkActiveTab ( activeTab : string ) : boolean {
66- return activeTab === 'overview' || activeTab === 'api' || activeTab === 'examples' ;
6742 }
6843
6944 onSelect ( tabName : string ) {
@@ -99,8 +74,4 @@ export class DocsSectionComponent implements OnDestroy {
9974 this . api = false ;
10075 this . examples = false ;
10176 }
102-
103- ngOnDestroy ( ) {
104- this . routeSubscription . unsubscribe ( ) ;
105- }
10677}
0 commit comments