Ionic tabs button not changing color when selected

Viewed 307

I'm trying to navigate to a path through tabs but selected tab color not changing when I use

tabs.html
<ion-tab-button [tab]="route">

tabs.ts

ngOnInit() {
    this.getId().get().subscribe((id) => {
        this.route = id;
    });
}

but when I remove [tab] to tab it works fine

I need to get route Id/params from server side.

1 Answers

To select programmatically one of the tabs you have at least two options.

Navigate to the desired tab:

import { IonTabs, NavController } from '@ionic/angular';

// add NavController to your constructor
constructor(private navCtrl: NavController) {}

// navigate by your route
this.navCtrl.navigateForward('/tabs/tab2');

Select tab:

import { Component, ViewChild } from '@angular/core';

// declare child's IonTab inside your component
@ViewChild(IonTabs) tabs: IonTabs;

// select your tab
this.tabs.select('tab2');
Related