Blame view

build/Button/Button.js 2.13 KB
3a3ecabe   Imshann   init
1
2
  import template from "./Button.html";
  import style from "antd/lib/button/style/index.css";
81f8a467   Imshann   调整组件前缀
3
  angular.module("esNgAntd").directive("antdButton", function (esNgAntd) {
3a3ecabe   Imshann   init
4
      return {
81f8a467   Imshann   调整组件前缀
5
          controllerAs: "antdButton",
3a3ecabe   Imshann   init
6
7
8
9
10
11
          restrict: "E",
          transclude: true,
          replace: true,
          scope: {
              type: "@",
              size: "@",
3a3ecabe   Imshann   init
12
13
14
15
16
              ghost: "@",
              loading: "@",
              htmlType: "@",
          },
          template: template,
061629e7   Imshann   add
17
          controller: function ($scope, $element, $attrs) {
3a3ecabe   Imshann   init
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
              this.getContext = function () {
                  return $scope;
              };
  
              $scope.state = {
                  disabled: null,
                  className: "",
              };
              $scope.watch = {
                  loading: (newVal) => {
                      if (newVal !== undefined) {
                          if (newVal === "true") {
                              $scope.state.className += " ant-btn-loading";
                          } else {
                              $scope.state.className =
                                  $scope.state.className.replace(
                                      " ant-btn-loading",
                                      ""
                                  );
                          }
                      }
                  },
              };
  
              for (const key in $scope.watch) {
                  $scope.$watch(key, $scope.watch[key], true);
              }
          },
          link: function ($scope, $element, $attrs, $controllers, $transclude) {
              esNgAntd.createStyle("ant-btn", style);
              let className = ["ant-btn"];
3a3ecabe   Imshann   init
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  
              if ($scope.type) {
                  className.push("ant-btn-" + $scope.type);
              }
  
              if ($scope.size && ["lg", "sm", "xs"].includes($scope.size)) {
                  className.push("ant-btn-" + $scope.size);
              }
  
              if ($scope.ghost) {
                  className.push("ant-btn-background-ghost");
              }
  
              $scope.state.className = className.join(" ");
  
              if ($scope.htmlType) {
                  $element[0].setAttribute("type", $scope.htmlType);
              }
          },
      };
  });