Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
Get Element Reference of a DOM Element created dynamically from a library

I want to add a class to a DOM Element by taking it's reference. But the element is created by a library and I cannot access it directly, means I can't use ViewChild or HostBinding on that DOM Element.

I can access it directly using document.querySelector(<.classname>) and then add another class to it. But it is Javascript, right? Is there any way to do it in Angular? How to do DOM Manipulation for a dynamically created DOM Element not having an id or #reference?

I want to add a class "hidden" to image layer element of Openlayers. I am using the above method but how to do it in angular?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use ElementRef. Simply inject ElementRef in your component and you can select the DOM element you want using its class. Im am assuming that the element that you are looking for already has another class which you can refer to. Here is an example implementation:

import {ElementRef} from '@angular/core';

export class MyClassComponent {

   constructor(private: elRef: ElementRef) {
   
      findMyElement(): void { 
         console.log(this.elRef.nativeElement.querySelector('.myclass'));
      }
   }
}

Please note that, querySelector will find the first occurrence of this element. Therefore, you have to use it with caution.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda