TabPane.js
1.24 KB
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
import template from "./TabPane.html";
angular.module("esNgAntd").directive("antdTabPane", function () {
return {
template: template,
restrict: "E",
replace: true,
transclude: true,
scope: {
key: "@",
tab: "@"
},
require: ["^antdTabs"],
controller: function ($scope, $element, $attrs) {
$scope.watch = {
tab: function (newVal) {
if (newVal) {
let item = $scope.antdTabs.state.labels.find(function (item) {
return item.key === $scope.key;
});
if (item) {
item.name = newVal;
}
}
}
};
$scope.state = {
activeKey: null,
key: $scope.key
};
},
link: function ($scope, $element, $attrs, $controllers) {
for (const key in $scope.watch) {
$scope.$watch(key, $scope.watch[key], true);
}
let [antdTabs] = $controllers;
if (antdTabs) {
$scope.antdTabs = antdTabs.getContext();
$scope.antdTabs.state.labels.push({
name: $scope.tab,
key: $scope.key
});
$scope.antdTabs.state.childrens.push($scope);
$scope.state.activeKey = $scope.antdTabs.state.activeKey;
}
}
};
});