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

212
Vistas
Angular4 - ngIf else with tabs

I have a dialog with different tabs. I want to use the tabs for users as well for group of users. The dialog is quite similar therefore I want to use it as a generic one.... Tabs are used from ngx-bootstrap (1.6.6)

<tabset> 
    <div *ngIf="isUserEditor; else groupDetails">
        <tab heading="User details">
                Details...content 4 user
         </tab>
    </div>  
    <ng-template #groupDetails>
        <tab heading="Group details">
                Group content
         </tab>
    </ng-template>
    <tab heading="Permissions">
                Permission settings 
    </tab>
</tabset>

I'm facing different problems:

  1. The above syntax for the if/else does not work. i.e. the content of UserDetails is displayed independent of the selected tab.

    a) Why is the content of UserDetails displayed in all tabs?

    b) If I change to if/then/else-Syntax UserDetails is not displayed in all tabs, but the tab-heading remains.

  2. The display order is annoying - namely I see the permission tab at the first position - but I want to have it on the last position. Is there a way to achieve it? Note: The UserDetails might be split up into more than one tab, the Permission tab might be not the last tab which will be added. I'm looking for a solution without too much code duplication.

  3. Is there a diff if I use for the *ngIf a div container or a ng-container?

Honestly I have no clue if this is bug in ngx-bootstrap or not... But it could be as well incorrect usage of syntax...

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

The following works:

  <tabset *ngIf="isUserEditor>=0">
     <div *ngIf="isUserEditor; then userDetails else groupDetails"></div>
     <ng-template #userDetails>
        <tab heading="User details">
            Details...content 4 user
        </tab>
     </ng-template>
     <ng-template #groupDetails>
        <tab heading="Group details">
            Group content
        </tab>
     </ng-template>
     <ng-container *ngIf="true">
        <tab heading="Permissions">
            Permission settings 
        </tab>
     </ng-container>
  </tabset>

The main trick consists of 2 parts:

  1. isUserEditor needs to be initialized to -1 and so the tabs are not rendered at the very beginning!
  2. If I place the last tab as well into a container ==> calculation if displayed or not are done at the very ending => order remains correct!
over 4 years ago · Santiago Trujillo Denunciar

0

1/3. For your first problem is because you are wrapping <tab> inside <div>. You dont need to handle visibility like that. There is a [active] input for <tab>:

<tabset>
    <tab header="User details" [active]="tabsActivity.tab1" (select)="tabToggle('tab1')">
        Details...content 4 user
    </tab>

    <tab header="Group details" [active]="tabsActivity.tab2" (select)="tabToggle('tab2')">
        Group content
    </tab>

    <tab header="Permissions" [active]="tabsActivity.tab3" (select)="tabToggle('tab3')">
        Permission settings
    </tab>
</tabset>

Where tabsActivity is a model for all states of tabs. (select) will toggle individual activity of tabs by chaning boolean state of tabsActivity properties.

  1. Problem with order will be resolved when you use [active].
over 4 years ago · Santiago Trujillo 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