-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-directive-tabs-card.html
119 lines (119 loc) · 4.41 KB
/
angular-directive-tabs-card.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>angular-directive-选项卡</title>
<script type="text/javascript" src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
.inline-block, .ib {
display: inline-block;
}
.pub-tabs-wrap {
position: relative;
}
.pub-tabs {
margin: 0;
padding: 45px 0px 27px 40px;
list-style: none;
background-color: #e6eaf5;
}
.pub-tabs li {
height: 18px;
margin-right: 60px;
cursor: pointer;
}
.pub-tabs li span:hover, .pub-tabs .active span {
color: #00a6e3;
}
.pub-tabs li a {
font: bold 14px "Microsoft Yahei";
color: #3c4457;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body ng-app="app" ng-controller="MyController">
<tab-card tab-datas="tab_datas" on-tab-click="tabClick(tab)"></tab-card>
<script type="text/html" id="tab-card">
<div class="pub-tabs-wrap">
<ul class="pub-tabs">
<li class="ib" ng-repeat="tab in tabDatas track by $index" ng-class="{'active': tab.isActive}" ng-click="onTabClick({tab: tab})">
<span>{{tab.text}}</span>
</li>
</ul>
</div>
</script>
<tab-card2 tab-datas="tab_datas2"></tab-card2>
<script type="text/html" id="tab-card2">
<div class="pub-tabs-wrap">
<ul class="pub-tabs">
<li class="ib" ng-repeat="tab in tabDatas track by $index" ng-class="{'active': tab.isActive}" ng-click="onTabClick(tab)">
<span>{{tab.text}}</span>
</li>
</ul>
</div>
</script>
<script type="text/javascript">
var app = angular.module('app', []);
app.controller('MyController', ['$scope', function($scope){
$scope.tab_datas = [
{text: 'tab1', isActive: 1},
{text: 'tab2', isActive: 0},
{text: 'tab3', isActive: 0}
];
$scope.tab_datas2 = [
{text: 'tab1', isActive: 1},
{text: 'tab2', isActive: 0},
{text: 'tab3', isActive: 0}
];
$scope.tabClick = function(tab){
angular.forEach($scope.tab_datas, function(v, k){
v.isActive = 0;
});
console.log(tab);
tab.isActive = 1;
};
}]);
app.directive('tabCard', function(){
return {
restrict: 'EA',
scope: {
tabDatas: '=',
onTabClick: '&'
},
template: function(){
return document.getElementById('tab-card').innerHTML;
},
controller: function($scope){
console.log($scope.onTabClick);
}
}
});
app.directive('tabCard2', function(){
return {
restrict: 'EA',
scope: {
tabDatas: '='
},
template: function(){
return document.getElementById('tab-card2').innerHTML;
},
controller: function($scope){
$scope.onTabClick = function(tab){
angular.forEach($scope.tabDatas, function(v, k){
v.isActive = 0;
});
console.log(tab);
tab.isActive = 1;
}
}
}
});
</script>
</body>
</html>