1

I have a component (table) that takes an array of any data. This component then calls a function in a service that requires a generic to determine what the data is (the function maps data).

However, I don't know of a way to using a generic with an Input / Component.

Anyone know how to do this?

When the component is used (in the template) on the parent level I would like to provide the actual Type of T. Any ideas?

@Component({
  selector: 'inm-mapped-table',
  template: `
  <pre>{{ $rows | async }} </pre>
  `,
})
export class InmMappedTableComponent<T extends Record<string, any>> implements OnInit {
  @Input() $data: Observable<T[]>;
  @Input() config: MappingConfig<T>[] = [];

  $rows: Observable<Row[]>;

  constructor(private readonly mappingService: InmTableMappingService) {}

  ngOnInit(): void {
    this.$rows = this.$data.pipe( 
        switchMap( data => this.mappingService.getRows<T>(data, this.config) )
    )
  }
}
0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.