You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
scrutiny/webapp/frontend/src/@treo/components/navigation/horizontal/components/basic/basic.component.ts

75 lines
2.3 KiB

import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { TreoHorizontalNavigationComponent } from '@treo/components/navigation/horizontal/horizontal.component';
import { TreoNavigationService } from '@treo/components/navigation/navigation.service';
import { TreoNavigationItem } from '@treo/components/navigation/navigation.types';
@Component({
selector : 'treo-horizontal-navigation-basic-item',
templateUrl : './basic.component.html',
styles : [],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TreoHorizontalNavigationBasicItemComponent implements OnInit, OnDestroy
{
// Item
@Input()
item: TreoNavigationItem;
// Name
@Input()
name: string;
// Private
private _treoHorizontalNavigationComponent: TreoHorizontalNavigationComponent;
private _unsubscribeAll: Subject<void>;
/**
* Constructor
*
* @param {TreoNavigationService} _treoNavigationService
* @param {ChangeDetectorRef} _changeDetectorRef
*/
constructor(
private _treoNavigationService: TreoNavigationService,
private _changeDetectorRef: ChangeDetectorRef
)
{
// Set the private defaults
this._unsubscribeAll = new Subject();
}
// -----------------------------------------------------------------------------------------------------
// @ Lifecycle hooks
// -----------------------------------------------------------------------------------------------------
/**
* On init
*/
ngOnInit(): void
{
// Get the parent navigation component
this._treoHorizontalNavigationComponent = this._treoNavigationService.getComponent(this.name);
// Subscribe to onRefreshed on the navigation component
this._treoHorizontalNavigationComponent.onRefreshed.pipe(
takeUntil(this._unsubscribeAll)
).subscribe(() => {
// Mark for check
this._changeDetectorRef.markForCheck();
});
}
/**
* On destroy
*/
ngOnDestroy(): void
{
// Unsubscribe from all subscriptions
this._unsubscribeAll.next();
this._unsubscribeAll.complete();
}
}