Blame view

build/Button/Button.js 1.48 KB
3a3ecabe   Imshann   init
1
  import style from "antd/lib/button/style/index.css";
2092c4d5   Imshann   优化
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
  import template from "./Button.html";
  angular.module("esNgAntd").directive("antdButton", ["esNgAntd", function (esNgAntd) {
    return {
      template: template,
      restrict: "E",
      replace: true,
      transclude: true,
      scope: {
        type: "@",
        size: "@",
        htmlType: "@",
        ghost: "=",
        loading: "@"
      },
      controller: function ($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", "");
3a3ecabe   Imshann   init
28
              }
2092c4d5   Imshann   优化
29
30
31
32
33
34
35
36
37
            }
          }
        };
      },
      link: function ($scope, $element, $attrs, $controllers, $transclude) {
        esNgAntd.createStyle("ant-btn", style);
          let className = ["ant-btn"];
          
          console.log($scope);
3a3ecabe   Imshann   init
38
  
2092c4d5   Imshann   优化
39
40
41
        if ($scope.type) {
          className.push("ant-btn-" + $scope.type);
        }
3a3ecabe   Imshann   init
42
  
2092c4d5   Imshann   优化
43
44
45
        if ($scope.size && ["lg", "sm", "xs"].includes($scope.size)) {
          className.push("ant-btn-" + $scope.size);
        }
3a3ecabe   Imshann   init
46
  
2092c4d5   Imshann   优化
47
48
49
        if ($scope.ghost) {
          className.push("ant-btn-background-ghost");
        }
3a3ecabe   Imshann   init
50
  
2092c4d5   Imshann   优化
51
        $scope.state.className = className.join(" ");
3a3ecabe   Imshann   init
52
  
2092c4d5   Imshann   优化
53
54
55
56
57
58
        if ($scope.htmlType) {
          $element[0].setAttribute("type", $scope.htmlType);
        }
      }
    };
  }]);