Skip to content

Instantly share code, notes, and snippets.

@pankajparkar
Last active March 31, 2019 11:20
Show Gist options
  • Save pankajparkar/d974554b217742359a2bb9c852d4619c to your computer and use it in GitHub Desktop.
Save pankajparkar/d974554b217742359a2bb9c852d4619c to your computer and use it in GitHub Desktop.
Tabs Directive with $scope
.directive('tabs', function() {
return {
restrict: 'E',
transclude: true,
scope: { },
controller: ['$scope', function TabsController($scope) {
var panes = $scope.panes = []
$scope.select = function(pane) {
angular.forEach(panes, function(p) {
p.selected = false;
});
pane.selected = true;
};
this.addPane = function(pane) {
if (panes.length === 0) {
$scope.select(pane);
}
$scope.panes.push(pane);
};
}],
templateUrl: 'tabs.html'
};
})
.directive('tab', function() {
return {
require: '^^tabs',
restrict: 'E',
transclude: true,
scope: { details: '<' },
link: function(scope, element, attrs, tabsCtrl) {
tabsCtrl.addPane(scope.details);
},
templateUrl: 'tab.html'
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment