Pass value from @Input to provided injection token

407 views Asked by At

How can i pass value from component @Input to provided InjectionToken ? Currently i have

@Component({
  selector: 'a-datetime',
  providers: [
    {provide: DateAdapter, useClass: MomentDateAdapter},
    {provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, 
      useValue: {strict: false, useUtc: ???}}, <-- Pass value from component @Input
  ]
})
export class DatetimeInputComponent implements OnInit {

  @Input() utc: boolean;

  constructor() {
  }

Idea is to use componet like:

<a-datetime [utc]="true or false"> depending on use case.

My current solution is to have / copy two components, one with <a-datetime-with-useutc-true and other <a-datetime-with-useutc-false and then i have <a-datetime where i decide which one to show with ngIf*

Im looking for more elegant solution. Can anyone point me to right direction ?

0

There are 0 answers