import { Component , ComponentFactoryResolver , ViewContainerRef , ChangeDetectionStrategy } from '@angular/core' ; import { ActivatedRoute , ActivatedRouteSnapshot } from '@angular/router' ; import { PageComponents } from './pages.module' ; import { Title } from '@angular/platform-browser' ; @ Component ( { changeDetection : ChangeDetectionStrategy . OnPush , template : ' ' } ) export class PageComponent { constructor ( private activatedRoute , private cfResolver , private viewContainer , private title ) { } ngOnInit ( ) { const content = this . activatedRoute . snapshot . data [ 'content' ] ; const ComponentClass = PageComponents . find ( component => component . ref === content [ 'template' ] ) ; this . title . setTitle ( content . title ) ; const pageComponentFactory = this . cfResolver . resolveComponentFactory ( ComponentClass ) ; const pageComponent = this . viewContainer . createComponent ( pageComponentFactory ) ; pageComponent . instance [ 'data' ] = content . data ; } }