Created
April 1, 2019 02:38
-
-
Save pankajparkar/2d677158aa4b877035d5eb524bd0cda6 to your computer and use it in GitHub Desktop.
Directive with controller as
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.directive('tabs', function() { | |
return { | |
restrict: 'E', | |
transclude: true, | |
scope: {}, | |
controllerAs: 'tabs', | |
controller: [function TabsController() { | |
var tabs = this; | |
var panes = tabs.panes = [] | |
tabs.select = function(pane) { | |
angular.forEach(panes, function(p) { | |
p.selected = false; | |
}); | |
pane.selected = true; | |
}; | |
tabs.addPane = function(pane) { | |
if (panes.length === 0) { | |
tabs.select(pane); | |
} | |
tabs.panes.push(pane); | |
}; | |
}], | |
templateUrl: 'tabs.html' | |
}; | |
}) | |
.directive('tab', function() { | |
return { | |
require: '^^tabs', | |
restrict: 'E', | |
transclude: true, | |
scope: {}, | |
bindToController: { | |
details: '<' | |
}, | |
controllerAs: 'tab', | |
link: function(scope, element, attrs, tabsCtrl) { | |
tabsCtrl.addPane(scope.tab.details); | |
}, | |
// controller is required to use bindToController | |
controller: function() {}, | |
templateUrl: 'tab.html' | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment