Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
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 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!