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

242
Visualizações
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 Respostas
Responde à pergunta

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 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