import { Component, Renderer } from '@angular/core'; @Component({ selector: 'app-root', template: '' }) export class AppComponent { constructor(private renderer: Renderer) {} onClick() { const btn = this.renderer.createElement('button'); this.renderer.setElementClass(btn, 'clicked', true); } }
import { Component, Renderer } from '@angular/core'; @Component({ selector: 'app-root', template: '' }) export class AppComponent { constructor(private renderer: Renderer) {} ngOnInit() { const circle = this.renderer.createElementNS('http://www.w3.org/2000/svg', 'circle'); this.renderer.setElementAttribute(circle, 'r', '50'); this.renderer.setElementAttribute(circle, 'cx', '50'); this.renderer.setElementAttribute(circle, 'cy', '50'); this.renderer.setElementStyle(circle, 'fill', 'red'); this.renderer.setElementStyle(circle, 'stroke', 'black'); this.renderer.setElementProperty(svg, 'appendChild', [circle]) } }The Renderer library is included in the @angular/core package. Developers can import the Renderer class from this package and use it in their components.