top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are the difference between Renderer and ElementRef in angular 2?

+1 vote
1,094 views
What are the difference between Renderer and ElementRef in angular 2?
posted Nov 16, 2017 by Jdk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

ElementRef vs. Renderer

In Angular Renderer and ElementRef are used for DOM Manipulation and Renderer and ElementRef are used together to get full platform abstraction.

Renderer

Renderer is a class that is a partial abstraction done the DOM manipulations and the DOM manipulating is not breaking server side rendering or web workers.

ElementRef

ElementRef is a class that is a partial abstraction done the DOM Manipulations without breakable environments and it also can hold a reference to a DOM elements.

If “ElementRef” is injected to a component, the injected instance is a reference to the host element of the current component.

The ways to get an ElementRef instance looks like,

1.     @ViewChild()
2.     @ViewChildren()
3.     @ContentChild()
4.     @ContentChildren()

In this case the ElementRef is a reference to the matching elements in the templates

answer Nov 28, 2017 by Manikandan J
...