Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit ab0387c

Browse files
bekospkozlowski-opensource
authored andcommitted
refactor(tabs): use optional binding for active
Closes #1713
1 parent 4f56e60 commit ab0387c

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

src/tabs/tabs.js

+2-22
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ angular.module('ui.bootstrap.tabs', [])
182182
templateUrl: 'template/tabs/tab.html',
183183
transclude: true,
184184
scope: {
185+
active: '=?',
185186
heading: '@',
186187
onSelect: '&select', //This callback is called in contentHeadingTransclude
187188
//once it inserts the tab's content into the dom
@@ -192,27 +193,7 @@ angular.module('ui.bootstrap.tabs', [])
192193
},
193194
compile: function(elm, attrs, transclude) {
194195
return function postLink(scope, elm, attrs, tabsetCtrl) {
195-
var getActive, setActive;
196-
if (attrs.active) {
197-
getActive = $parse(attrs.active);
198-
setActive = getActive.assign;
199-
scope.$parent.$watch(getActive, function updateActive(value, oldVal) {
200-
// Avoid re-initializing scope.active as it is already initialized
201-
// below. (watcher is called async during init with value ===
202-
// oldVal)
203-
if (value !== oldVal) {
204-
scope.active = !!value;
205-
}
206-
});
207-
scope.active = getActive(scope.$parent);
208-
} else {
209-
setActive = getActive = angular.noop;
210-
}
211-
212196
scope.$watch('active', function(active) {
213-
// Note this watcher also initializes and assigns scope.active to the
214-
// attrs.active expression.
215-
setActive(scope.$parent, active);
216197
if (active) {
217198
tabsetCtrl.select(scope);
218199
}
@@ -226,7 +207,7 @@ angular.module('ui.bootstrap.tabs', [])
226207
}
227208

228209
scope.select = function() {
229-
if ( ! scope.disabled ) {
210+
if ( !scope.disabled ) {
230211
scope.active = true;
231212
}
232213
};
@@ -236,7 +217,6 @@ angular.module('ui.bootstrap.tabs', [])
236217
tabsetCtrl.removeTab(scope);
237218
});
238219

239-
240220
//We need to transclude later, once the content container is ready.
241221
//when this link happens, we're inside a tab heading.
242222
scope.$transcludeFn = transclude;

0 commit comments

Comments
 (0)