import { Renderer2, ElementRef } from '@angular/core'; constructor(private renderer: Renderer2, private el: ElementRef) {} addClass() { const divElem = this.el.nativeElement.querySelector('div'); this.renderer.addClass(divElem, 'myClassName'); }
const button = this.renderer.createElement('button'); const text = this.renderer.createText('Click me!'); this.renderer.appendChild(button, text); this.renderer.appendChild(document.body, button);In this example, we use Renderer2 to create a button element and add it to the DOM using the createElement() and appendChild() methods. Overall, @angular/core Renderer2 is a crucial angular package library that simplifies the manipulation of HTML elements and data binding to improve application performance.