Topic: Changing Tab from typescript
mog5808 pro asked 7 years ago
tabset
from typescript
.
It appears selectedIndex
does not work.
Here is what i tried
HTML
<tabset #tabGroup [buttonStyle]="'nav-tabs tabs-2 unique-color'" [contentStyle]="'card'" [selectedIndex]="selectedIndex">
Calling the TS method
<li (click)="changeTab('1')">
TS
changeTab(tabIndex) {
this.selectedIndex = tabIndex;
}
mog5808 pro answered 7 years ago
@ViewChild('teamTabs') public teamTabs;
and
changeTab(tabIndex) {
this.teamTabs.setActiveTab(tabIndex);
}
It only worked when i changed it to
@ViewChild('teamTabs') public tabs;
and
changeTab(tabIndex) {
this.tabs.setActiveTab(tabIndex);
}
I have no idea why but the above worked and thanks for your time mate
Cheers,
Rafał Rogulski free answered 7 years ago
import { Component, ViewChild } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
@ViewChild('tabs') public test;
changeTab() {
this.test.setActiveTab(3);
}
}
app.component.html:
<!-- Tabset tabs -->
<tabset #tabs [buttonStyle]="'nav-tabs tabs-3 red'" [contentStyle]="'card'">
<!--Panel 1-->
<tab ripple-radius heading="Profile">
<div class="row">
<div class="col-12">
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil odit magnam minima, soluta doloribus reiciendis molestiae placeat unde eos molestias. Quisquam aperiam, pariatur. Tempora, placeat ratione porro voluptate odit minima.</p>
</div>
</div>
</tab>
<!--Panel 2-->
<tab ripple-radius heading="Follow">
<div class="row">
<div class="col-12">
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil odit magnam minima, soluta doloribus reiciendis molestiae placeat unde eos molestias. Quisquam aperiam, pariatur. Tempora, placeat ratione porro voluptate odit minima.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil odit magnam minima, soluta doloribus reiciendis molestiae placeat unde eos molestias. Quisquam aperiam, pariatur. Tempora, placeat ratione porro voluptate odit minima.</p>
</div>
</div>
</tab>
<!--Panel 3-->
<tab ripple-radius heading="Contact">
<div class="row">
<div class="col-12">
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil odit magnam minima, soluta doloribus reiciendis molestiae placeat unde eos molestias. Quisquam aperiam, pariatur. Tempora, placeat ratione porro voluptate odit minima.</p>
<p>Last</p>
</div>
</div>
</tab>
</tabset>
<button (click)="changeTab()">Set Last</button>
Also, chceck console if you don't have any errors.
Rafał Rogulski free answered 7 years ago
mog5808 pro answered 7 years ago
ts
?
I tried the following
@ViewChild('your_id') public your_id;
changeTab(){
this.your_id.setActiveTab(2);
}
Any ideas?
Rafał Rogulski free answered 7 years ago
#your_id
,
then you cane use it in this same component:
<button ripple-radius (click)="your_id.setActiveTab(1)">1</button>
tabs are starting from 1!
Regards
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
- ForumUser: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: Yes
- Provided link: No