Blame view

build/TabPane/TabPane.js 1.24 KB
3a3ecabe   Imshann   init
1
  import template from "./TabPane.html";
81f8a467   Imshann   调整组件前缀
2
  angular.module("esNgAntd").directive("antdTabPane", function () {
6674355b   Imshann   优化选项阿凯
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    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;
              });
3a3ecabe   Imshann   init
20
  
6674355b   Imshann   优化选项阿凯
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
              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);
        }
3a3ecabe   Imshann   init
36
  
6674355b   Imshann   优化选项阿凯
37
        let [antdTabs] = $controllers;
3a3ecabe   Imshann   init
38
  
6674355b   Imshann   优化选项阿凯
39
40
41
42
43
44
45
46
47
48
49
50
        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;
        }
      }
    };
  });