I\'m looking for a way to instantiate a component in Angular2 from within the code of another component. Unlike the many people that have asked a similar question I\'m not so mu
There seems to be a (new?) API function for doing what is described in mxii's answer. The ViewContainerRef has the createComponent
method. It instantiates the component and adds it to the view.
let factory = this._cmpFctryRslvr.resolveComponentFactory(AnyComponent);
let cmp = this.viewContainer.createComponent(factory);
cmp.instance.name = 'peter';