Is it possible to enable or disable a tab in Ionic3?

Is it possible to enable and disable a tab in Ionic3 application?

I try to use *ngIf to do that in html, but each time when setting is changed from false to true, an new tab is added; when setting is changed from true to false, the tab doesn’t disappear.

html is:

<ion-tabs>
  <ion-tab [root]="tab0Root" [tabTitle]="tab0Title" tabIcon="home"></ion-tab>
  <ion-tab [root]="tab1Root" [tabTitle]="tab1Title" tabIcon="people"></ion-tab>
  <ion-tab *ngIf="setting==true" [root]="tab2Root" [tabTitle]="tab2Title" tabIcon="setting"></ion-tab>
</ion-tabs>

Thanks.

Yes, but use the enabled property documented here. Do not use ngIf for this, and incidentally always use ===, never ==, and similarly never explicitly compare against true. Just let setting speak for itself, or if absolutely necessary to cast to a boolean, use !!setting.

2 Likes

Thanks! It is really helpful.