File

projects/core/src/routing/facade/routing-params.service.ts

Description

Service to expose all parameters for the router, including child routes. This is convenient in case the parent route (component) requires awareness of child routes parameters.

Index

Properties
Methods

Constructor

constructor(router: Router, activatedRoutesService: ActivatedRoutesService)
Parameters :
Name Type Optional
router Router No
activatedRoutesService ActivatedRoutesService No

Methods

Protected findAllParam
findAllParam(routes: ActivatedRouteSnapshot[])
Parameters :
Name Type Optional
routes ActivatedRouteSnapshot[] No
Returns : literal type
getParams
getParams()

Get the list of all parameters of the full route. This includes active child routes.

Returns : Observable<literal type>

Properties

Protected Readonly params$
Type : Observable<literal type>
Default value : this.activatedRoutesService.routes$.pipe( map((routes) => this.findAllParam(routes)), shareReplay({ refCount: true, bufferSize: 1 }) )
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { map, shareReplay } from 'rxjs/operators';
import { ActivatedRoutesService } from '../services/activated-routes.service';

/**
 * Service to expose all parameters for the router, including child routes.
 * This is convenient in case the parent route (component) requires awareness
 * of child routes parameters.
 */
@Injectable({ providedIn: 'root' })
export class RoutingParamsService {
  protected readonly params$: Observable<{
    [key: string]: string;
  }> = this.activatedRoutesService.routes$.pipe(
    map((routes) => this.findAllParam(routes)),
    shareReplay({ refCount: true, bufferSize: 1 })
  );

  constructor(
    protected router: Router,
    protected activatedRoutesService: ActivatedRoutesService
  ) {}

  /**
   * Get the list of all parameters of the full route. This includes
   * active child routes.
   */
  getParams(): Observable<{ [key: string]: string }> {
    return this.params$;
  }

  protected findAllParam(routes: ActivatedRouteSnapshot[]): {
    [key: string]: string;
  } {
    return Object.assign({}, ...routes.map((route) => route.params));
  }
}

result-matching ""

    No results matching ""