Topic: MdbTabsComponent setActiveTab not working

tech pro asked 2 years ago


I am using angular mdbtabs with latest version 5.

I am generating the tabs using nfFor as the tabs are dynamic. The active tab is not set ever after i am setting on the ts file

ngOnInit(): void {

this.tabs.tabs.first.active = true
this.tabs.setActiveTab(1)

} ngAfterViewInit(): void { this.tabs.tabs.first.active = true this.tabs.setActiveTab(1) }


noveltytech priority answered 5 months ago


Is this fixed? I still can't manually set the active tab. I am on Angular 17 MDB5 v6


Rafał Seifert free commented 5 months ago

Please refer to our API section in official docs. We have example for using setActiveTab method: https://mdbootstrap.com/docs/angular/navigation/tabs/#api-section-methods


shellxsoftware free answered 1 year ago


same issue here, any fix?


Arkadiusz Idzikowski staff answered 2 years ago


Please try to use this code as a workaround for now, we will take a closer look at that to check if we can change something in the component code to fix that:

  ngAfterViewInit() {
    Promise.resolve().then(() => {
      this.tabs.setActiveTab(1);
    });
  }

Lumpenstein free commented 1 year ago

Hello,

I am facing a similar bug when trying to set the last active tab index (read from localstorage). When the Tab component gets mounted it is triggering the onTabChange event with the index of the first tab, is there a way to prevent this? (a property like 'triggeredByUser' would suffice as well).



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: MDB5 2.0.0
  • Device: PC
  • Browser: chrome
  • OS: Windowns
  • Provided sample code: No
  • Provided link: No