Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
enhance(tabs): added $materialTabs service
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBurleson committed Sep 9, 2014
1 parent e6943b4 commit 738bb42
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/sidenav/sidenav.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ function materialSidenavController($scope, $element, $attrs, $timeout, $material
*
* ```javascript
* // Toggle the given sidenav
* $materialSidenav.toggle(componentId);
* $materialSidenav(componentId).toggle();
*
* // Open the given sidenav
* $materialSidenav.open(componentId);
* $materialSidenav(componentId).open();
*
* // Close the given sidenav
* $materialSidenav.close(componentId);
* $materialSidenav(componentId).close();
* ```
*/
function materialSidenavService($materialComponentRegistry) {
Expand Down
42 changes: 42 additions & 0 deletions src/components/tabs/js/tabsController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
angular.module('material.components.tabs')
.factory('$materialTabs', [
'$materialComponentRegistry',
TabsService
])
.controller('materialTabsController', [
'$scope',
'$attrs',
Expand All @@ -8,6 +12,44 @@ angular.module('material.components.tabs')
]);


/**
* @private
* @ngdoc service
* @name $materialTabs
* @module material.components.tabs
*
* @description
* $materialTabs makes it easy to programmatically interact with a specific Tabs group
* in an app.
*
* @usage
*
* ```javascript
* // Toggle the given sidenav
* $materialTabs(tabsID).select(0);
* ```
*/
function TabsService($materialComponentRegistry) {
return function(handle) {
var instance = $materialComponentRegistry.get(handle);
if(!instance) {
$materialComponentRegistry.notFoundError(handle);
}

return {
/**
* Select the tab at the specified index
* @param index
* @returns {*}
*/
select: function(index) {
return instance && instance.selectAt(index);
}
};
};
}


/**
* @ngdoc object
* @name materialTabsController
Expand Down

0 comments on commit 738bb42

Please sign in to comment.