Created
April 20, 2014 04:03
-
-
Save izumin5210/11104645 to your computer and use it in GitHub Desktop.
【AngularJS】タブでコンテンツ切り替えするやつ
This file contains 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
<div class="tab-pane" ng-show="active" ng-transclude> | |
</div> |
This file contains 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
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) |
This file contains 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
<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> |
This file contains 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
<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