0

When some data arrives from an API I need to perform a click event in my Angular app. It has to be done from typescript code. I use a component from an external library and it is the only way to make it work as I need.

I used ViewChild as ElementRef. Then called click() on the native element of this elementRef, but I read everywhere that it's unsafe. I also read about using Renderer2 instead, but it is able to change only reaction to events or style of the DOM element.

So is there any better way of doing that?

André
  • 1,602
  • 2
  • 12
  • 26
  • Hello, why would you say, from your readings, that ViewChild is unsafe ? – Alain Boudard Jun 28 '22 at 13:13
  • I found it here and it refears to Angular documentation https://www.techiediaries.com/angular-elementref/ – thortineoc Jun 28 '22 at 13:26
  • I see, okay. I'm not sure if that would be appropriate, but when dealing with external libraries, I have worked with Outside of Zone like this : https://indepth.dev/posts/1434/running-event-listeners-outside-of-the-ngzone – Alain Boudard Jun 28 '22 at 13:54

0 Answers0