component-register.service.ts 577 B

123456789101112131415161718192021222324
  1. import { Injectable, Type } from '@angular/core';
  2. import { Map } from '../utils/js-utils';
  3. // tslint:disable-next-line: no-any
  4. const COMPONENT_MAP: Map<Type<any>> = {};
  5. // tslint:disable-next-line: no-any
  6. export function register(dataType: Type<any>) {
  7. // tslint:disable-next-line: no-any
  8. return (cls: Type<any>) => {
  9. COMPONENT_MAP[dataType.name] = cls;
  10. };
  11. }
  12. @Injectable({
  13. providedIn: 'root',
  14. })
  15. export class ComponentRegisterService {
  16. // tslint:disable-next-line: no-any
  17. getComponent(dataType: Type<any>) {
  18. return COMPONENT_MAP[dataType.name];
  19. }
  20. }