@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>
61 lines (57 loc) • 2.96 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import * as i0 from '@angular/core';
import { ElementRef, Renderer2, Directive, Input } from '@angular/core';
import * as i1 from '@angular/router';
import { NavigationEnd, Router } from '@angular/router';
import { asArray } from '@ng-doc/core/helpers/as-array';
import { untilDestroyed, UntilDestroy } from '@ngneat/until-destroy';
import { filter, map, distinctUntilChanged } from 'rxjs/operators';
let NgDocRouteActiveDirective = class NgDocRouteActiveDirective {
constructor(elementRef, router, renderer) {
this.elementRef = elementRef;
this.router = router;
this.renderer = renderer;
this.link = '';
this.activeClass = [];
this.matchOptions = {
fragment: 'exact',
paths: 'subset',
queryParams: 'exact',
matrixParams: 'exact',
};
this.router.events
.pipe(filter((event) => event instanceof NavigationEnd), map(() => this.router.isActive(this.link, this.matchOptions)), distinctUntilChanged(), untilDestroyed(this))
.subscribe((isActive) => {
isActive
? asArray(this.activeClass).forEach((cls) => this.renderer.addClass(this.elementRef.nativeElement, cls))
: asArray(this.activeClass).forEach((cls) => this.renderer.removeClass(this.elementRef.nativeElement, cls));
});
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgDocRouteActiveDirective, deps: [{ token: i0.ElementRef }, { token: i1.Router }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive }); }
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.0.3", type: NgDocRouteActiveDirective, isStandalone: true, selector: "[ngDocRouteActive]", inputs: { link: ["ngDocRouteActive", "link"], activeClass: "activeClass", matchOptions: "matchOptions" }, ngImport: i0 }); }
};
NgDocRouteActiveDirective = __decorate([
UntilDestroy(),
__metadata("design:paramtypes", [ElementRef,
Router,
Renderer2])
], NgDocRouteActiveDirective);
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgDocRouteActiveDirective, decorators: [{
type: Directive,
args: [{
selector: '[ngDocRouteActive]',
standalone: true,
}]
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.Router }, { type: i0.Renderer2 }], 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