Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda