UNPKG

@this-dot/route-config

Version:

A library containing directives and services for configuring components via Route's routeData property

49 lines (48 loc) 2.26 kB
import { OnDestroy, OnInit, TemplateRef, ViewContainerRef } from '@angular/core'; import { RouteConfigService, RouteData } from '../route-config.service'; import * as i0 from "@angular/core"; export interface RouteDataDirectiveContext<C> { $implicit: C; } /** * This directive allows for access to the whole `data` property defined in the current [Route](https://angular.io/api/router/Route#data) from a Component's template. * * @example * <!-- We can use it as following: --> * <h1 *tdRouteData="let data"> * Current title is: {{ data.title }} * </h1> * * @example * <!-- It is also possible to pass a default value so that if a property is not defined in the Route we will still receive some value: --> * <h1 *tdRouteData="let data; defaultValue: { title: 'DefaultTitle', routeTags: ['defaultTag'] }"> * Current title is: {{ data.title }} * </h1> * * @example * <!-- If you want to access multiple properties in one component's template it is **recommended** to wrap the whole template with only one `*tdRouteData` directive. This approach follows DRY principle and is efficient as it only creates one subscription per template. --> * <ng-container *tdRouteData="let data; defaultValue: { title: 'DefaultTitle', routeTags: ['defaultTag'] }"> * <h1> * Current title is: {{ data.title }} * </h1> * <p> * Current route contains the following tags: {{ data.routeTags | json }} * </p> * </ng-container> */ export declare class RouteDataDirective<C extends RouteData> implements OnInit, OnDestroy { private routeConfigService; private template; private entry; private destroy$; private defaultValue$; private view; private data$; private createView$; set tdRouteDataDefaultValue(defaultValue: C); constructor(routeConfigService: RouteConfigService, template: TemplateRef<RouteDataDirectiveContext<C>>, entry: ViewContainerRef); ngOnInit(): void; ngOnDestroy(): void; static ɵfac: i0.ɵɵFactoryDeclaration<RouteDataDirective<any>, never>; static ɵdir: i0.ɵɵDirectiveDeclaration<RouteDataDirective<any>, "[tdRouteData]", never, { "tdRouteDataDefaultValue": { "alias": "tdRouteDataDefaultValue"; "required": false; }; }, {}, never, never, false, never>; }