Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. <div [ngSwitch]="variant.type">
  2. <div *ngSwitchCase="'typeA'">
  3. <typeAComponent></typeAComponent>
  4. </div>
  5. <div *ngSwitchCase="'typeB'">
  6. <typeBComponent></typeBComponent>
  7. </div>
  8. <div *ngSwitchCase="'typeC'">
  9. <typeCComponent></typeCComponent>
  10. </div>
  11. </div>
  12.  
  13. $myClassName = 'myClass';
  14. $instance = new $myClassName();
  15.  
  16. //inject the component factory resolver
  17. constructor(private componentFactoryResolver:ComponentFactoryResolver){}
  18.  
  19. //accept a component and a viewContainerRef (where you want to load the component)
  20. loadComponent(component:Type, target:ViewContainerRef){
  21. let componentFactory = this.componentFactoryResolver.resolveComponentFactory(component);
  22. target.createComponent(componentFactory);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement