What's your best practice to avoid a component to trigger multiple times the same function when leaving and coming back to some page ?
I went into this issue when creating a user list that would trigger some getContent()
each time the user scroll to the bottom of the page. The problem is each time you leave and come back to user list page, it will create a new instance of the service and trigger x times the getContent()
function.
I'm using ngOnDestroy()
and reset the getContent()
method to avoid multiple calls but I'm sure either there's something wrong in my code or there is a best way to do it... Than :
ngOnDestroy() {
this.items.clear();
this.getContent = ():void => {};
};
Thanks a lot for your advices/opinions.
M
PS: plnkr is down, I will post one ASAP