Blame view

build/FormItem/FormItem.js 1.28 KB
3a3ecabe   Imshann   init
1
2
  /**
   * 表单域
3a3ecabe   Imshann   init
3
4
   */
  import template from "./FormItem.html";
81f8a467   Imshann   调整组件前缀
5
  angular.module("esNgAntd").directive("antdFormItem", function () {
50f4289a   Imshann   优化Form组件
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    return {
      template: template,
      restrict: "E",
      replace: true,
      transclude: true,
      scope: {
        name: "@",
        label: "@",
        labelCol: "=",
        wrapperCol: "=",
        required: "="
      },
      require: ["^?antdForm"],
      controller: function ($scope, $element, $attrs) {
        this.getContext = function () {
          return $scope;
        };
3a3ecabe   Imshann   init
23
  
50f4289a   Imshann   优化Form组件
24
25
26
27
28
29
30
        $scope.state = {
          labelCol: null,
          wrapperCol: null
        };
      },
      link: function ($scope, $element, $attrs, $controllers) {
        let [antdForm] = $controllers;
3a3ecabe   Imshann   init
31
  
50f4289a   Imshann   优化Form组件
32
33
34
        if (antdForm) {
          $scope.antdForm = antdForm.getContext();
        }
3a3ecabe   Imshann   init
35
  
50f4289a   Imshann   优化Form组件
36
37
38
39
40
41
42
43
44
45
46
47
48
49
        if ($scope.labelCol && $scope.labelCol.span) {
          $scope.state.labelCol = $scope.labelCol.span;
        } else if ($scope.antdForm.labelCol && $scope.antdForm.labelCol.span) {
          $scope.state.labelCol = $scope.antdForm.labelCol.span;
        }
  
        if ($scope.wrapperCol && $scope.wrapperCol.span) {
          $scope.state.wrapperCol = $scope.wrapperCol.span;
        } else if ($scope.antdForm.wrapperCol && $scope.antdForm.wrapperCol.span) {
          $scope.state.wrapperCol = $scope.antdForm.wrapperCol.span;
        }
      }
    };
  });