Angular 2: Load component dynamically with parameters @Input and @Output -


currently i'm loading of components dynamically piece of code.

export class componentoutlet {      constructor(         private vcref: viewcontainerref,         private compiler: compiler,         private dataservice: dataservice     ) { }      private _createdynamiccomponent() {          // logic decide component should loaded         return mycomponent;     }       ngonchanges() {          this.compiler.compilecomponentasync(this._createdynamiccomponent())             .then(factory => {                 const injector = reflectiveinjector.fromresolvedproviders([], this.vcref.parentinjector);                 this.vcref.clear();                 this.vcref.createcomponent(factory, 0, injector);             });     } 

the problem mycomponent has @input , output bindings. possible set bindings here? how can achieve that?

bindings inputs , outputs can used components statically added components template.

in case can imperatively like

 var cmpref = this.vcref.createcomponent(factory, 0, injector);  cmpref.instance.someinput = value;  cmpref.instance.someoutput.subscribe(data => this.data = data); 

Comments