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

166
Visualizações
How to use JS function in Angular (component.ts) Collapsible Sidebar

I am trying to collapse an already existing Sidebar in an Angular project. The Sidebar is implemented in the app.component.html. I am trying to make it it's own component.

I'm trying to add this JS function to the sidebar.component.ts file.

{
  const sideBar = document.querySelector('.side-bar');
  const arrowCollapse = document.querySelector('#logo-name__icon');
  sideBar.onclick = () => {
    sideBar.classList.toggle('collapse');
    arrowCollapse.classList.toggle('collapse');
    if (arrowCollapse.classList.contains('collapse')) {
      arrowCollapse.classList =
        'bx bx-arrow-from-left logo-name__icon collapse';
    } else {
      arrowCollapse.classList = 'bx bx-arrow-from-right logo-name__icon';
    }
  };
}

I need to be able to toggle the sidebar closed so that the full text isnt showing anymore next to the icons but just the icons.

I'm following this guide and it should look like that in the end: https://www.cssscript.com/smooth-collapsible-sidebar-navigation/

But I can't get the JS to work. I'm checking first if this would work before I implement it. I'm not allowed to use Jquery/Alpine.js nor other external libraries. We are using Tailwind and not Bootstrap.

Thank you a lot!!!

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

0

You should consider using *ngIf to toggle certain elements instead of using the DOM object.

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