Save State of Tab content when changing Route with angularjs and BootStrap Tabs

你说的曾经没有我的故事 提交于 2019-12-12 05:40:01

问题


I have 3 tree bootstrap tabs in my angular application.

<ul class="nav nav-tabs">
  <li><a href="" ng-click="changeRoute(1)">Tab 1</a></li>
  <li><a href="" ng-click="changeRoute(2)">Tab 2</a></li>
  <li><a href="" ng-click="changeRoute(3)">Tab 3</a></li>
</ul>

and in my controller i change the route when changeRoute() called :

 $scope.changeRoute = function(id){
  $location.path('/tabs/'+id);
 }

each tab have a same view and in view i have html select :

<select>
  <option>Item 1</option>
  <option>Item 2</option>
  <option>Item 3</option>
  <option>Item 4</option>
</select>

now when Route change new view come. i need when Route change browser or angular save the state of selected index of select in each view. so if in tab 1 user select item 1 in select then user click on tab 2 and change the select and then change the route to tab 1 user can see the item 1 selected in tab 1. i create a small simulation of this scenario in plunker

this plunker is a simulation that what i want without changing route.but i have many thing in view and i think it is better to use route.

来源:https://stackoverflow.com/questions/23404348/save-state-of-tab-content-when-changing-route-with-angularjs-and-bootstrap-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!