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/

Related Posts:

  • HostListener event key Angular 2+ Event key Angular 2+ Angular 2+ @HostListener('window:keydown', ['$event']) keyboardInput(event: any) { event.preventDefault(); event.stopPropagation(); this.which = event.which; this.keyCode = … Read More
  • Validation formBuilder trong Angular 2+ Validation FormBuilder Bước 1: Tạo project Angular 2 bấm vào đây app.component.ts Angular 2+ import { FormGroup, FormBuilder, Validators } from '@angular/forms'; constructor(private formBuilder… Read More
  • HostListener event scroll Angular 2+ Event scroll Angular 2+ Angular 2+ import { Component, HostListener, Inject, NgModule, OnInit } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { D… Read More
  • HostBinding và HostListener Angular 2+ HostBinding và HostListener app.component.html Angular 2+ <h2 class="high-light">Hello color host binding</h2> <input hostTest type="text"/> host-color.directive.ts Angular 2+ import { Dire… Read More
  • ControlValueAccessor TwoWay Binding trong Angular 2+  ControlValueAccessor TwoWay Binding interface ControlValueAccessor { writeValue(obj: any): void; registerOnChange(fn: any): void; registerOnTouched(fn: any): void; setDisabledState?(isDisabled: boolean… Read More

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang