It is my understanding that it is bad practice in Angular to interact with DOM elements directly and that Renderer2 should be used instead. I have noticed however that Renderer2 is full of setter methods (setStyle, setProperty, setValue, etc..), but there are no getter methods. How should one obtain DOM element properties without interacting with the element directly, i.e elementRef.nativeElement.<propertyOfInterest>
?
Example:
- Get
scrollTop
value of Element: elementRef.nativeElement.scrollTop
- Set
scrollTop
value of Element: renderer.setProperty(elementRef.nativeElement, 'scrollTop', myValue)
If this is the only way to get element property values, then why does that not defeat the purpose of Renderer2?
Reference Material: