J
J
Jan2018-03-21 15:14:13
JavaScript
Jan, 2018-03-21 15:14:13

How to correctly remove an Angular component?

Hello!
I have a method that creates a component

manualParsing(): {
    var component = this.cfr.resolveComponentFactory(LeadTemplateLoaderComponent);
    this.tableViewComp = this.tableViewContainer.createComponent(component);
    this.tableViewComp.instance._ref = this.tableViewComp;
    this.tableViewComp.instance.loadedDataResponse = this.data;
    this.tableViewComp.instance.currentFilePath = this.requestData.FilePath;
    //etc
}

It is created, they work with it. And there is another method that accesses the instance of this component and looks at its boolean
if (this.tableViewComp.instance.isTemplateLoaded) {
      this.tableViewComp.destroy();
      this.manualParsing();
      //Method for new component
      this.DoSomeWithNewComponent()
    }

That is, it must check if true, then it removes the current component and creates a new one via the manualParsing() method;
The problem is that DoSomeWithNewComponent() does not work on a new component. In the debug, I saw that it does this:
1) Destroy() is called on the current component.
2) A new component is created via manualPearsing();
3) DoSomeWithNewComponent() works on the old component.
4) The old component is removed
5) The new component, respectively, without changes
How can this issue be resolved?
Climbed off. Documentation, Google, found nothing useful there.
PS Angularv 4.4.3

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question