@ng-doc/app
Version:
<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>
53 lines (49 loc) • 2.5 kB
JavaScript
import * as i0 from '@angular/core';
import { inject, ElementRef, Renderer2, Input, Directive } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { Router, NavigationEnd } from '@angular/router';
import { asArray } from '@ng-doc/core/helpers/as-array';
import { filter, map, distinctUntilChanged } from 'rxjs/operators';
class NgDocRouteActiveDirective {
constructor() {
this.link = '';
this.activeClass = [];
this.matchOptions = {
fragment: 'exact',
paths: 'subset',
queryParams: 'exact',
matrixParams: 'exact',
};
const elementRef = inject(ElementRef);
const router = inject(Router);
const renderer = inject(Renderer2);
router.events
.pipe(filter((event) => event instanceof NavigationEnd), map(() => router.isActive(this.link, this.matchOptions)), distinctUntilChanged(), takeUntilDestroyed())
.subscribe((isActive) => {
isActive
? asArray(this.activeClass).forEach((cls) => renderer.addClass(elementRef.nativeElement, cls))
: asArray(this.activeClass).forEach((cls) => renderer.removeClass(elementRef.nativeElement, cls));
});
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: NgDocRouteActiveDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.6", type: NgDocRouteActiveDirective, isStandalone: true, selector: "[ngDocRouteActive]", inputs: { link: ["ngDocRouteActive", "link"], activeClass: "activeClass", matchOptions: "matchOptions" }, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: NgDocRouteActiveDirective, decorators: [{
type: Directive,
args: [{
selector: '[ngDocRouteActive]',
standalone: true,
}]
}], ctorParameters: () => [], propDecorators: { link: [{
type: Input,
args: ['ngDocRouteActive']
}], activeClass: [{
type: Input
}], matchOptions: [{
type: Input
}] } });
/**
* Generated bundle index. Do not edit.
*/
export { NgDocRouteActiveDirective };
//# sourceMappingURL=ng-doc-app-directives-route-active.mjs.map