Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2: ElementRef nativeElement vs querySelector performance

Tags:

angular

There are times when I have to go for DOM event listners and since

I'm more familiar with querySelector I can use it with more ease.

But I wonder what does ElementRef has to offer and which one is better.

like image 334
Ankit Singh Avatar asked Mar 08 '16 08:03

Ankit Singh


1 Answers

ElementRef and Renderer provide an abstraction of a part of the DOM API which allows to execute some DOM related actions when no actual browser DOM is available like it is the case when the Angular application is executed by the server or in a WebWorker. Not using this abstraction might prevent your application to utilize server-side-rendering or WebWorkers.

like image 144
Günter Zöchbauer Avatar answered Sep 25 '22 07:09

Günter Zöchbauer