-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Tabs - Dynamically created tabs do not respond to "select" or execute it immediately on creation #1496
Comments
Kept playing with this and figured out following. One cannot define select as option but rather bind it the markup. So my markup now looks like this <tab data-ng-repeat="tab in tabs" heading="{{tab.title}}" active="{{tab.active}}" select="activateTab(tab.name)" class="fullwidthtabs">
<div ng-include="tab.content"></div>
</tab> However I still have an issue with tab not being shown as selected :( |
Have you tried doing If that doesn't work, please post a Plunker demonstrating this issue so we can look into this further. |
Yes, I figured that one out :), however one more issue that I am trying to figure out is that it selects the first tab as active even when all tabs are set initially to be inactive. In my setup each tab has its own controller. I have a requirement that I need to link to specific tab based on the user selection on the previous page, and make that tab active. So, I set them all to active="false", then wait for all controllers to emit a message that they are created, and then I match the routeParam with tab name and broadcast a message to activate tab, which in turn runs a fetch method and selects the tab. But because it defaults to the first tab as being active if none are made active, I end up broadcasting the message twice, once for the first tab, and once for the one that has been selected. However, if I set |
The reason this is done is that this is usually the desired behavior of tabs. If no tab is selected, the first one is picked to be active. I'm on the fence on this behavior. Some people consider the state where no tabs are selected to be invalid. This requires more feedback from community. |
Hmm, I don't think we should allow a state where there is no active tab, at lest this is my point of view. More generally, those repeated issues with tabs active property make me think that maybe we've got the API wrong? Maybe, instead of having an active flag on each tab, we should have something like "active index" on the tabset level? Same applies to accordion. WDYT? |
+1 to move the active property to |
Ah, you are right @bekos, I've forgotten that we've added ability to have multiple groups open. |
I agree with switching the implementation to keeping the active tab index at the tabset level. I think the most common use case of the active flag at the tab level, is the ability for a tab to find out whether it is currently active. I don't think it is as likely that a tab's contents or controller would set itself to be active. We could instead use use getters and setters for changing the active tab on the tabset controller. Similar to the ngForm directive's name attribute, we can publish the tabset controller into the scope for tabs to set/getActiveTab if an attribute is set. And perhaps add a new onActive attribute which takes a function (an '&' attribute) and fires on activation of a new tab. (There are multiple suggestions here, but they're all for consideration individually, not pushing for all or none.) |
I am also having this issue. I create the Tabs with ng-repeat, and each tab has a select assigned to it, as soon as the 2nd tab is created it calls the select, as it assumes the first tab should be active, when in fact its the third (as yet un-rendered) tab i want to have as active. This means the functions is called twice. |
any progress on this issue? |
Closing, as this looks like a non-issue. For progress on fixing the API, keep an eye on #4836. |
If one creates a dynamic tab like this
then function specified for "select" will execute right away while tabs are being constructed. I tried also using just "activateTab" without parenthesis and that does not do anything. You can try it also just using a plunker supplied with tabs example and try to put select for dynamic tab 1
and you will see the issue. Also setting the "active" attribute to true from javascript code does not do anything either. My markup for the tabs is like this
The text was updated successfully, but these errors were encountered: