admin管理员组文章数量:1399887
I have tabs inside a modal with this code:
<ion-tabs class="tabs-positive tabs-top">
<ion-tab title="FIND">
<ion-view>
<ion-content>
<div class="list list-inset">
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" ng-model="data.sight" placeholder="Find events or people" ng-change="searchSight()">
</label>
</div>
</ion-content>
</ion-view>
</ion-tab>
<ion-tab>
... More tabs
</ion-tab>
</ion-tabs>
And I have a footer button that I want to perform a particular action according to the active tab, How do I get the active tab in Ionic?
Thank you very much!
I have tabs inside a modal with this code:
<ion-tabs class="tabs-positive tabs-top">
<ion-tab title="FIND">
<ion-view>
<ion-content>
<div class="list list-inset">
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" ng-model="data.sight" placeholder="Find events or people" ng-change="searchSight()">
</label>
</div>
</ion-content>
</ion-view>
</ion-tab>
<ion-tab>
... More tabs
</ion-tab>
</ion-tabs>
And I have a footer button that I want to perform a particular action according to the active tab, How do I get the active tab in Ionic?
Thank you very much!
Share Improve this question asked Jul 7, 2015 at 20:38 MiguelMiguel 1,6562 gold badges17 silver badges29 bronze badges2 Answers
Reset to default 3You could get the selected index of your tab using the $ionicTabsDelegate, which could possibly help you determine what action to take.
function MyCtrl($scope, $ionicTabsDelegate) {
if ($ionicTabsDelegate.selectedIndex() == 0){
// Perform some action
}
}
Use the $getByHandle method to control specific ionTabs instances.
Example:
$ionicTabsDelegate.$getByHandle('my-handle').selectedIndex();
Explained in further detail at the $ionicTabsDelegate API Documentation
As far as I know, Ionic uses ui-router. To get the current state in UI-router, you can use the $state directive described in ui-router's API documentation here.
The 2 methods that might interest you are probably:
$state.is('state-name');
$state.includes('part-of-state-name-');
You'll need to make sure that you have $state injected into the footer's controller if you want to reference it directly in the html, or you can define a scope method or variable if you want to take that logic off the controller.
本文标签: javascriptHow to get the active tab in IonicStack Overflow
版权声明:本文标题:javascript - How to get the active tab in Ionic - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744157035a2593154.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论