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

139
Visualizações
Scroll from element to an another component's element

I have this problem for days and I could not figure this out (also im pretty new in Angular). My goal would be to have an element in a component like this. Lets called this A element:

<button (click)="scroll('anotherComponentsElementId')">Services</button>

the function:

  scroll(id: string) {
    let el = document.getElementById(id);
    console.log(id);
    el!.scrollIntoView();
  }

And then I have an another component, which has the element, where I would like to scroll. Lets call this B element:

<section class="page-section" id='anotherComponentsElementId'>lets gooo</section>

How can I scroll from A element to B element? Currently the code doesnt work, because in the function the id is null. Would you be so kind to help me out?

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

0

You can try to add onclick="location.href='#elementid'" in your button.

<input id='top' type="button" onclick="location.href='#A'" value="go to A" />
<input type="button" onclick="location.href='#B'" value="go to B" />
<input type="button" onclick="location.href='#C'" value="go to C" />
<br><br>
<section id='A' style='background:red'>section 1</section>
<p>line</p>
<p>line</p>
<p>line</p>
<p>line</p>
<input type="button" onclick="location.href='#top'" value="back to top" />
<br><br>
<section id='B' style='background:green'>section 2</section>
<p>line</p>
<p>line</p>
<p>line</p>
<p>line</p>
<input type="button" onclick="location.href='#top'" value="back to top" />
<br><br>
<section id='C' style='background:blue'>section 3</section>
<p>line</p>
<p>line</p>
<p>line</p>
<p>line</p>
<input type="button" onclick="location.href='#top'" value="back to top" />
<br><br><br>

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