[英]How to get the active tab in Ionic
我在模態代碼中包含以下標簽:
<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>
我有一個頁腳按鈕,我想根據活動選項卡執行特定的操作, 如何在Ionic中獲得活動選項卡?
非常感謝你!
您可以使用$ ionicTabsDelegate獲取選項卡的選定索引,這可能有助於您確定要采取的操作。
function MyCtrl($scope, $ionicTabsDelegate) {
if ($ionicTabsDelegate.selectedIndex() == 0){
// Perform some action
}
}
使用$ getByHandle方法控制特定的ionTabs實例。
例:
$ionicTabsDelegate.$getByHandle('my-handle').selectedIndex();
在$ ionicTabsDelegate API文檔中有更詳細的解釋
據我所知,Ionic使用ui-router。 要獲取UI-router中的當前狀態,可以使用ui-router的API文檔中所述的$ state指令。
您可能感興趣的2種方法可能是:
$state.is('state-name');
$state.includes('part-of-state-name-');
如果要直接在html中引用它,則需要確保已將$ state注入到頁腳的控制器中,或者,如果要從控制器中刪除該邏輯,則可以定義一個范圍方法或變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.