Skip to content

Instantly share code, notes, and snippets.

@izumin5210
Created April 20, 2014 04:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izumin5210/11104645 to your computer and use it in GitHub Desktop.
Save izumin5210/11104645 to your computer and use it in GitHub Desktop.
【AngularJS】タブでコンテンツ切り替えするやつ
<div class="tab-pane" ng-show="active" ng-transclude>
</div>
app = angular.module 'MyApplication'
app.directive 'tabSet', ->
restrict: 'E'
replace: true
templateUrl: 'templates/tabset.html'
transclude: true
scope: {}
controller: ($scope, TimetablesService) ->
tabs = $scope.tabs = []
@addTab = (tab) ->
tabs.push tab
tab.active = (tabs.length == 0)
$scope.select = (tab) ->
angular.forEach tabs, (tab) -> tab.active = false
tab.active = true
return
link: (scope, element, attrs, ctrl) ->
app.directive 'tabPane', ->
require: '^tabSet'
restrict: 'E'
replace: true
templateUrl: 'templates/tab.html'
transclude: true
scope:
heading: '@'
link: (scope, element, attrs, ctrl) ->
ctrl.addTab(scope)
<div>
<ul>
<li ng-repeat="tab in tabs" ng-class="{active: tab.active}">
<a ng-click="select(tab)">{{tab.heading}}</a>
</li>
</ul>
<div ng-transclude>
</div>
</div>
<tab-set>
<tab-pane heading="tab1">
タブ1のコンテンツ
</tab-pane>
<tab-pane heading="tab2">
タブ2のコンテンツ
</tab-pane>
<tab-pane heading="tab3">
タブ3のコンテンツ
</tab-pane>
</tab-set>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment