1

I have a component that listens for a click event, simplified parts below:

@Component({
    selector: '[sortable-column]',
    templateUrl: './sortable-column.component.html'
})
export class SortableColumnComponent implements OnInit, OnDestroy {
    @HostListener('click') doSomething() {
    }

    constructor() {
    }

    ngOnInit() {
    }

    ngOnDestroy() {
    }
}

and the template:

 <th sortable-column>name</th>

When running this, if I never click on the <th> the component get's garbage collected properly, if I do click on it, then the component gets stuck in memory... I thought that the HostListener cleaned up the underlying event handler?

What am I missing here?

Thibs
  • 8,058
  • 13
  • 54
  • 85
  • Please see the below answer to unregister the listener. https://stackoverflow.com/questions/46389002/how-to-listen-for-mousemove-event-on-document-object-in-angular/46389054#46389054 – Sudhakar May 17 '18 at 15:02
  • Does the problem appear even if you do nothing in the `click` event handler? – ConnorsFan May 17 '18 at 15:07
  • @ConnorsFan, yes that is correct, I tried with and without doing anything in the handler... – Thibs May 17 '18 at 15:10

0 Answers0