Problem Statement
Why use Renderer2 instead of direct DOM access?
Explanation
Renderer2 abstracts DOM operations so your code works in different platforms (browser, server, web workers) and reduces XSS risks by enforcing safe operations. It also improves testability.
Code Solution
SolutionRead Only
constructor(private r: Renderer2, private host: ElementRef){}
ngOnInit(){ this.r.setAttribute(this.host.nativeElement,'role','button'); }