3

I'm combining 2 responses from 2 api-calls into one. After the 2 responses are done, the combining function should be triggered.

I have managed to do this whit a ngDoCheck() as follows:

ngDoCheck() {
    if(this.tasksResponse && this.peopleResponse && !this.peopleShown) {
        this.finalData = this.returnPeople.mapData(this.peopleResponse, this.tasksResponse);
        this.peopleShown = true;
    }
}

As you can see, I check if the responses are in, and I check for the 'this.peopleShown' boolean. In the constructor I set this to 'false'. The reason I do this, is because I don't want the function to run every time a small thing changes (when the user interacts with the site for instance).

With my solution the ngDoCheck() has no impact after it ran successfully once, so it works the way I want to. My only concern is that the lifecycle hook is still hooked (like an eventlistener, that keeps listening, but doesn't do anything). Perfomance-wise not the best solution I think?

My question
Is it possible to unhook the ngDoCheck() in any way?
ngStopCheck(), or something..

vjawala
  • 67
  • 3
  • Good one, should save some performance. I'm still looking if it's possible to unhook the hook (something like 'removeEventlistener') – vjawala Jul 14 '16 at 07:54

0 Answers0