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

241
Views
How to have different components in the ngbNav tabs?

I am using Angular and ngbNav to create tabs. The problem is that I have tab names from the API and to show them I need ngFor, but also for the content of the tab I should show different components. To implement that I have used ngSwitch.

<ul ngbNav #nav="ngbNav" class="nav-tabs">
          <li ngbNavItem *ngFor="let element of elements" [ngSwitch]="element.name">
            <a ngbNavLink>{{element.name}}</a>
            <ng-template ngbNavContent *ngSwitchCase="'Super Item'">
              <app-super-item
              ></app-super-item>
            </ng-template>

            <ng-template ngbNavContent *ngSwitchCase="'Another Item'">
              <app-another-item
              ></app-another-item>
            </ng-template>
            <ng-template ngbNavContent *ngSwitchDefault><div>Default</div></ng-template>
          </li>
        </ul>
        <div [ngbNavOutlet]="nav"></div>

I do not know how to activate the first tab in this case. Everything works but only after clicking on the tab. I would like to have the first tab active by default.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I would add the component as a key/value pair in the elements object. Then you could grab it in the for loop with {{element.component}}.

about 4 years ago · Santiago Trujillo 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!