Last active
March 31, 2019 11:20
-
-
Save pankajparkar/d974554b217742359a2bb9c852d4619c to your computer and use it in GitHub Desktop.
Tabs Directive with $scope
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: { }, | |
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