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

515
Visualizações
How to set iframe height dynamically in angular 9?

I am trying to achieve this by 'ngAfterViewInit' and '@ViewChild('iframeContainer') iframeContainer: ElementRef;'

<iframe #iframeContainer [src]="iframeUrl" id="kfsFrame" width="100%" frameBorder="0"></iframe>

.TS FILE CODE :


  ngAfterViewInit(): void {
    this.injectIframe();
  }

 private injectIframe(): void {
    const iframe = this.iframeContainer.nativeElement;

    const height:any = Math.max( iframe.scrollHeight, iframe.offsetHeight, 

      iframe.clientHeight, iframe.scrollHeight, iframe.offsetHeight );

    iframe.setAttribute('width', '100%');

   console.log(height);

    iframe.setAttribute('height', height);

    iframe.setAttribute('frameBorder', '0');

    iframe.addEventListener('load', this.iframeOnLoadtwo);
 }

  public iframeOnLoadtwo(): void {
    console.log('iframe loaded...');
  }```
_______________________________________________

While consoling height [console.log(height);] in console log, it is taking default height which is very less than iframe content height. Currently iframe having scroller bar which I don't want and want height to fit the content.
about 4 years ago · Juan Pablo Isaza
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