angular.module('tasks', ['ngRoute']) .directive('tabs', function () { return { restrict: 'A', transclude: true, scope: { style: "@tabs" }, controller: [ "$scope", function ($scope) { $scope.panels = []; $scope.select = function (i) { angular.forEach($scope.panels, function (p) { p.selected = false; }); $scope.panels[i].selected = true; }; this.addPanel = function (panel) { if ($scope.panels.length === 0) { panel.selected = true; } $scope.panels.push(panel); }; }], template: '
' + '
' + '
' + '
', replace: true }; }) .directive('panel', function () { return { require: '^tabs', restrict: 'A', transclude: true, scope: { title: "@panel" }, link: function (scope, element, attrs, tabsCtrl) { tabsCtrl.addPanel(scope); }, template: '
' + '
', replace: true }; }) .config(function ($routeProvider) { $routeProvider. when('/', {templateUrl: 'templates/main.html', controller: 'MainCtrl'}). otherwise({redirectTo: '/'}); });