I am using Primeng Tabview in my angular application. I have the code as shown below to set the active tab using code.
<button (click)="change(0)">First</button>
<button (click)="change(1)">Second</button>
<button (click)="change(2)">Third</button>
<p:tabView [activeIndex]="index" ...
public index: number;
change(index: number): void {
this.index = index;
}
But as soon as I manually go to a tab and try to click on the button, it is not going to the right tab. Not sure what is wrong or how to make it work?
Update your index
variable while changing tab manually.
HTML
<p-tabView [activeIndex]="index" (onChange)="handleChange($event)">...
TS
handleChange(e) {
this.index = e.index;
}
See Plunker
Alternatively, use two-way binding:
<p-tabView [(activeIndex)]="index"></p-tabView>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With