thisdot / open-source

Repository for open source packages
MIT License
34 stars 11 forks source link

Create directive to give access to route config in template #47

Closed ktrz closed 3 years ago

ktrz commented 3 years ago

Is your feature request related to a problem? Please describe.

It would be great to be able to access route's data directly from a template using a structural directive.

Describe the solution you'd like

We could create a tsRouteConfig structural directive to expose the route's data in the template

<ng-container *tdRouteConfig="let config">
  <h1>{{ config.title }}</h1>
<ng-container>

This would simplify the example with a title we have. However, we might need a way to add a default value somehow (in case eg. title is we want a default title everywhere apart from some specific routes). I think we can provide it either via an injection token (eg. TD_ROUTE_CONFIG_DEFAULT_VALUE) or via a second property for this directive

<ng-container *tdRouteConfig="let config" [tdRouteConfigDefaultValue]="{ title: 'Default Title' }">
  <h1>{{ config.title }}</h1>
<ng-container>

And the property would take precedence over the injection token value.