09 August 2020

Renderer2 in Angular

import {Injectable, Renderer2, RendererFactory2} from '@angular/core';

@Component({
  selector: 'app-example',
  templateUrl: './example.component.html',
  styleUrls: ['./example.component.scss'],
})
export class ExampleComponent {

  constructor (private renderer: Renderer2) { }

  createRecaptchaContainer() {
    // Use Angular's Renderer2 to create the div element
    const recaptchaContainer = this.renderer.createElement('div');
    // Set the id of the div
    this.renderer.setProperty(recaptchaContainer, 'id', 'recaptcha-container');
    // Append the created div to the body element
    this.renderer.appendChild(document.body, recaptchaContainer);

    return recaptchaContainer;
  }
}

https://www.positronx.io/using-renderer2-angular/

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang