angularjs - Angular 2 - Create Component Dynamically - Is it mandatory to call 'detach()' method on the component reference? -


i have angular 2 app need create child components dynamically.

is mandatory call 'detectchanges()' , 'detach()' method on component reference variable 'componentref.changedetectorref' ?

i see things work if dont use them.

are these methods meant component injection performance improvement ?

@component({     selector: 'container',     template: '<template #content></template>' }) export class containercomponet implements afterviewinit {     contentcomponentref:any;     @viewchild('content', {read: viewcontainerref}) contenthandle;      constructor(private componentresolver:componentresolver) {         super();     }      ngafterviewinit() {          if (this.contentcomponentref)            this.contentcomponentref.destroy();       this.componentresolver.resolvecomponent(childcomponent)       .then((factory:componentfactory<any>) => {           let componentref = this.contenthandle.createcomponent(factory);            componentref.instance['child_component_property'] = 'dummy value child';            componentref.changedetectorref.detectchanges();           componentref.ondestroy(() => {               componentref.changedetectorref.detach();           });           this.contentcomponentref = componentref;           return componentref;      });     }      } 


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -