import { ComponentFactory , ComponentFactoryResolver , Injectable , Type } from '@angular/core' ; import { IDocumentationPage } from '../../interfaces/IDocumentationPage' ; import * as chartsPage from '../../data/charts-page.json' ; import * as componentsPage from '../../data/components-page.json' ; import * as cssPage from '../../data/css-page.json' ; @ Injectable ( { providedIn : 'root' } ) export class ResolverService { private static resolvers : DocumentationResolver [ ] = [ ] ; registerResolver ( resolver , components ) { ResolverService . resolvers . push ( { resolver , components } ) ; } resolveComponentFactory ( component ) { for ( const { resolver , components } of ResolverService . resolvers ) { if ( components . indexOf ( component ) !== - 1 ) { return resolver . resolveComponentFactory ( component ) ; } } throw new Error ( 'Component does not exist in any module: ' + component ) ; } static resolveCategoryData ( page , categoryTitle ) { let data ; switch ( page ) { case DocumentationPage . Charts : data = chartsPage as IDocumentationPage ; break ; case DocumentationPage . Components : data = componentsPage as IDocumentationPage ; break ; case DocumentationPage . Css : data = cssPage as IDocumentationPage ; break ; } let match = data . categories . find ( category => category . title === categoryTitle ) ; if ( ! match ) { throw new Error ( `The section "${ categoryTitle }" does not exist!` ) ; } return match ; } } export enum DocumentationPage { Charts , Components , Css } export interface DocumentationResolver { resolver : ComponentFactoryResolver ; components : Type < any > [ ] ; }