Skip to content

Instantly share code, notes, and snippets.

@pankajparkar
Created April 1, 2019 02:38
Show Gist options
  • Save pankajparkar/2d677158aa4b877035d5eb524bd0cda6 to your computer and use it in GitHub Desktop.
Save pankajparkar/2d677158aa4b877035d5eb524bd0cda6 to your computer and use it in GitHub Desktop.
Directive with controller as
.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