0

Is it better in Angular 2+ to capture events using () in HTML:

<h1 (click)="onClick($event)"></h1>

Or using listen method of Renderer2:

renderer.listen(element, 'click', (event) => {
  onClick(event);
});

Thanks

Raphael
  • 563
  • 1
  • 10
  • 22
  • https://stackoverflow.com/a/35082441/8505598 Check that – Aya Abdelaziz May 13 '18 at 10:29
  • @AyaAbdelaziz I already read that, however almost everywhere when we search on the web the first way comes first. If the second way is the best, why the first one exists and why there are fewer resources on that? – Raphael May 13 '18 at 10:40

1 Answers1

0

Both of them are completely fine. But, in case you need to manipulate the DOM, the safest way of doing it is using the renderer.

Pedro Martín
  • 136
  • 1
  • 7