import { ChangeDetectionStrategy , ChangeDetectorRef , Component , ComponentFactoryResolver , ViewChild , ViewContainerRef } from '@angular/core' ; @ Component ( ( { selector : 'second-side-menu-container' , changeDetection : ChangeDetectionStrategy . OnPush , template : '<template #secondaryContainer></template>' } ) ) export class SecondSideMenuContainerComponent { @ ViewChild ( 'secondaryContainer' , { read : ViewContainerRef } ) container ; constructor ( private componentFactoryResolver , private cdRef ) { } resolveComponent ( component ) { this . container . clear ( ) ; const componentFactory = this . componentFactoryResolver . resolveComponentFactory ( component ) ; this . container . createComponent ( componentFactory ) ; this . cdRef . detectChanges ( ) ; } clear ( ) { this . container . clear ( ) ; } }