Files
ionic-framework/js/angular/service/tabsDelegate.js
Adam Bradley 3baa66c313 refactor(delegateService): expose ionic.DelegateService
This change makes the DelegateService available on the ionic namespace.
It is useful so external directives can follow the delegate pattern set
by the framework itself.
2014-12-12 20:33:02 -06:00

64 lines
1.6 KiB
JavaScript

/**
* @ngdoc service
* @name $ionicTabsDelegate
* @module ionic
*
* @description
* Delegate for controlling the {@link ionic.directive:ionTabs} directive.
*
* Methods called directly on the $ionicTabsDelegate service will control all ionTabs
* directives. Use the {@link ionic.service:$ionicTabsDelegate#$getByHandle $getByHandle}
* method to control specific ionTabs instances.
*
* @usage
*
* ```html
* <body ng-controller="MyCtrl">
* <ion-tabs>
*
* <ion-tab title="Tab 1">
* Hello tab 1!
* <button ng-click="selectTabWithIndex(1)">Select tab 2!</button>
* </ion-tab>
* <ion-tab title="Tab 2">Hello tab 2!</ion-tab>
*
* </ion-tabs>
* </body>
* ```
* ```js
* function MyCtrl($scope, $ionicTabsDelegate) {
* $scope.selectTabWithIndex = function(index) {
* $ionicTabsDelegate.select(index);
* }
* }
* ```
*/
IonicModule
.service('$ionicTabsDelegate', ionic.DelegateService([
/**
* @ngdoc method
* @name $ionicTabsDelegate#select
* @description Select the tab matching the given index.
*
* @param {number} index Index of the tab to select.
*/
'select',
/**
* @ngdoc method
* @name $ionicTabsDelegate#selectedIndex
* @returns `number` The index of the selected tab, or -1.
*/
'selectedIndex'
/**
* @ngdoc method
* @name $ionicTabsDelegate#$getByHandle
* @param {string} handle
* @returns `delegateInstance` A delegate instance that controls only the
* {@link ionic.directive:ionTabs} directives with `delegate-handle` matching
* the given handle.
*
* Example: `$ionicTabsDelegate.$getByHandle('my-handle').select(0);`
*/
]));