TabView Cannot use activeIndex to select new tab created in same lifecycle
I'm submitting a ... (check one with "x")
[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
Current behavior p-tabView with a number of p-tabPanels generated using *ngFor to iterate an array activeIndex bound to a variable
<p-tabView [activeIndex]="tabIndex">
<p-tabPanel *ngFor="let date of dates; first as isFirst" [header]="date" [selected]="isFirst">
stuff
</p-tabPanel>
<p-tabView>
in the same event lifecycle modify the date array so that a new tab will be created and set the tabIndex variable (bound to activeIndex) so that the new tab will be selected.
Result: the tab following the new tab is selected. Also if the activeIndex is set to one less than the index of the new tab then the tab previous to the new tab is selected. Basically the index is used to select a tab before the new tab is added.
Expected behavior That the new tab is selected. i.e activeIndex is used to select the correct tab after all the tabPanel elements have been generated.
What is the motivation / use case for changing the behavior? it's not possible to programatically add a new tab and make it selected
The work around is to hook into the AfterViewChecked lifecycle event and set the index at this point - this works but produces errors and is less than ideal.
-
Angular version: 4.2.6
-
PrimeNG version: 4.1.0
-
Browser: chrome 55.0.2883.87 m
-
Language: TypeScript 2.2.2
I don't know if this will be of any help, but I did something similar to this in a project for the sake of loading dynamic components. I used @ViewChildren over the dynamic components and watched for changes. Here's a plunkr with dates.
Great - that hooks into the correct part of the lifecycle to make the change. the tab I add is not always at the end but I can make that work. Thank you!