Can I bind an action to a tab bar button?


#1

click the button not go other page , just run some code.
thanks.


Intercept tab click and cancel the action?
#2

I think you’d really be fighting a losing battle to try to make that happen. Tabs are designed for windowed content. The controller for the tab component is designed to show different content based on which tab you are in.

If you want tab like buttons without actual tabs, I’d suggest putting icons / buttons in a footer. That way you get to do things based on clicks and aren’t trying to fight the built-in logic of tabs.


#3

Here’s a rough sample:


#4

I found the answer !
http://ionicframework.com/docs/angularjs/controllers/tab-bar/

at the bottom of the page.
it works great !

<ion-tabs tabs-type="tabs-icon-only">
  <ion-tab title="Home" icon-on="ion-ios7-filing" icon-off="ion-ios7-filing-outline" ng-controller="HomeCtrl">
    <ion-header-bar type="bar-positive" title="'Home'"></ion-header-bar>
    <ion-content has-header="true">
      <h2>Home Content</h2>
    </ion-content>
  </ion-tab>
</ion-tabs>

angular.module('test', ['ionic'])
.controller('HomeCtrl', function($scope) {
  $scope.$on('tab.shown', function() {
    // Maybe load some content here
  });
  $scope.$on('tab.hidden', function() {
    // Perhaps cycle out some data in memory here
  });
});

#5

I apologize for not understanding your intent. I thought you didn’t want tapping the tab bar to actually switch to another tab. Good job finding the solution.