In order to create block component dynamically, it is important to import following AppComponent such as-

  • ViewContainerRef, ComponentFactoryResolver and ViewChild from @angular/core
  • MessageComponent from message.component.
  • ComponentFactory and ComponentRef [email protected]/core

Example

                                        

import {
   Component,
   ViewContainerRef,
   ViewChild,
  ComponentFactoryResolver,
  ComponentRef,
  ComponentFactory
}

from '@angular/core';
import { MessageComponent } from './message.component';
@Component(
{
   selector: 'app-root',
   templateUrl: './app.component.html'
}
)
export class AppComponent {
  title = 'app';
}

Suggest An Answer

No suggestions avaliable!