rpocklin / ui-router-tabs

Idiot-proof tab panes with route support using Angular.js + Bootstrap 3 + UI Router
Other
244 stars 57 forks source link

Controller runs more than once after changing tab #76

Closed zhanghuanchong closed 8 years ago

zhanghuanchong commented 8 years ago

After clicking on the 2nd tab, the code in the tab's controller runs 4 times.

I also have a tabs with only 2 tab page, and the controller of the active one runs 2 times.

Can you help?

SugdenM commented 8 years ago

I have this issue as well. It appears that the tabs controller runs for the same number of times for which you have tabs. ie: 2 tabs = 2 executions, 3 tabs = 3 executions and so on.

On inspection it appears to be injecting the in each tab that is defined.

cegbert-wondersign commented 8 years ago

Hi guys... I had to solve this issue as well. The issue is that the <ui-view> directive which is rendered by ui-router is placed under each tab in the default template.

To solve, we used a custom template (just use the attribute template-url in the tabs directive), that did a simple check:

<ui-view ng-if="activeTab == $index"></ui-view>

You can currently use tabs.active instead of activeTab (see my open issue to address the activeTab naming: https://github.com/rpocklin/ui-router-tabs/issues/75)

rpocklin commented 8 years ago

Plunkrs would be useful here. Keep in mind there was a breaking change in v2.0.0 changing the default template to include a <ui-view> element. If you have upgraded and using the default template most likely you have duplicate <ui-view> elements causing the symptoms you mention.

I have found a bug in the placement of the <ui-view> element in the default template so i'll push that as v2.0.2, let me know if that fixes it.

titobf commented 8 years ago

v2.0.2 solved the issue for me

zhanghuanchong commented 8 years ago

Thank you Robert, the v2.0.2 works! 👍

MicrowaveDev commented 8 years ago

Yes, it solved this issue, but now ui-view not inside .tab-content and .tab-pane. And tab template has no tab variable :(