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

Commit

Permalink
update(tabs): rolls back manual two-way binding of 'selectedIndex' fo…
Browse files Browse the repository at this point in the history
…r simplicity's sake
  • Loading branch information
Robert Messerle committed Jul 1, 2015
1 parent f5cd5a0 commit a161013
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
31 changes: 7 additions & 24 deletions src/components/tabs/js/tabsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ angular
* @ngInject
*/
function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $mdTabInkRipple,
$mdUtil, $animate, $attrs, $compile, $mdTheming, $parse) {
$mdUtil, $animate, $attrs, $compile, $mdTheming) {
//-- define private properties
var ctrl = this,
locked = false,
Expand All @@ -15,9 +15,6 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
destroyed = false,
loaded = false;

//-- define two-way binding
defineBinding('selectedIndex', 'mdSelected', 0, handleSelectedIndexChange);

//-- define public properties with change handlers
defineProperty('focusIndex', handleFocusIndexChange, ctrl.selectedIndex || 0);
defineProperty('offsetLeft', handleOffsetChange, 0);
Expand All @@ -34,6 +31,7 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md

//-- define public properties
ctrl.scope = $scope;
ctrl.parent = $scope.$parent;
ctrl.tabs = [];
ctrl.lastSelectedIndex = null;
ctrl.hasFocus = false;
Expand Down Expand Up @@ -68,12 +66,14 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
function init () {
ctrl.selectedIndex = ctrl.selectedIndex || 0;
compileTemplate();
configureWatchers();
bindEvents();
$mdTheming($element);
$timeout(function () {
updateHeightFromContent();
adjustOffset();
updatePagination();
updateInkBarStyles();
ctrl.tabs[ctrl.selectedIndex] && ctrl.tabs[ctrl.selectedIndex].scope.select();
loaded = true;
});
Expand All @@ -87,7 +87,7 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
var template = $attrs.$mdTabsTemplate,
element = angular.element(elements.data);
element.html(template);
$compile(element.contents())(ctrl.scope);
$compile(element.contents())(ctrl.parent);
delete $attrs.$mdTabsTemplate;
}

Expand All @@ -99,25 +99,8 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
$scope.$on('$destroy', cleanup);
}

/**
* Defines a two-way data-binding without requiring an isolated scope.
* @param key
* @param attr
* @param defaultValue
* @param handler
*/
function defineBinding (key, attr, defaultValue, handler) {
var value = defaultValue, model;
defineProperty(key, function (newValue, oldValue) {
model && model.assign && model.assign(ctrl.scope, newValue);
handler(newValue, oldValue);
}, value);
if ($attrs.hasOwnProperty(attr)) {
model = $parse($attrs[attr]);
$scope.$watch($attrs[attr], function (newValue) {
ctrl[key] = newValue || 0;
});
}
function configureWatchers () {
$scope.$watch('$mdTabsCtrl.selectedIndex', handleSelectedIndexChange);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/components/tabs/js/tabsDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ angular

function MdTabs ($mdTheming, $mdUtil, $compile) {
return {
scope: {
selectedIndex: '=?mdSelected',
},
template: function (element, attr) {
attr["$mdTabsTemplate"] = element.html();
return '\
Expand Down Expand Up @@ -193,6 +196,7 @@ function MdTabs ($mdTheming, $mdUtil, $compile) {
';
},
controller: 'MdTabsController',
controllerAs: '$mdTabsCtrl'
controllerAs: '$mdTabsCtrl',
bindToController: true
};
}

0 comments on commit a161013

Please sign in to comment.