I'm trying to inject a component on a container dinamically
Component:
@Component({...})
export class InvestmentProcess{
@ViewChild('container') container;
constructor(public dcl: DynamicComponentLoader) {}
loadComponent(fooComponent: Type){
this.dcl.loadNextToLocation(fooComponent, container);
}
}
Template:
<div #container> </div>
When I run the function loadComponent the following error is thrown:
TypeError: location.createComponent is not a function
That's becouse container is an ElementRef typed variable, and loadNextToLocation expects a ViewContainerRef as the second parameter. As official docs said, the ViewContainerRef can be extracted from an element via @ViewChild, but I haven't find any example to do it properly.
Working with Angular2.0.0rc1