Blame view

build/Slot/Slot.js 1.36 KB
81f8a467   Imshann   调整组件前缀
1
  angular.module("esNgAntd").directive("antdSlot", function ($compile) {
3a3ecabe   Imshann   init
2
      return {
81f8a467   Imshann   调整组件前缀
3
          controllerAs: "antdSlot",
3a3ecabe   Imshann   init
4
5
6
7
8
9
10
          restrict: "E",
          transclude: true,
          replace: true,
          scope: {
              content: "@",
              context: "=",
          },
e7610b68   Imshann   feat(pagination):...
11
          controller: function ($scope, $element, $attrs) {
3a3ecabe   Imshann   init
12
13
14
15
16
17
18
19
              this.getContext = function () {
                  return $scope;
              };
  
              $scope.watch = {
                  content: (newValue) => {
                      if (newValue !== undefined) {
                          if (/<[^>]+>/.test(newValue)) {
a5fb53e0   Imshann   优化
20
21
22
23
24
25
26
                              $scope.parentElement
                                  .empty()
                                  .append(
                                      $compile(newValue)(
                                          $scope.context ? $scope.context : $scope
                                      )
                                  );
3a3ecabe   Imshann   init
27
28
29
30
31
32
33
34
35
36
37
                          } else {
                              $element.text(newValue);
                          }
                      }
                  },
              };
  
              for (const key in $scope.watch) {
                  $scope.$watch(key, $scope.watch[key], true);
              }
          },
a5fb53e0   Imshann   优化
38
39
40
          link: function ($scope, $element, $attrs, $controllers, $transclude) {
              $scope.parentElement = $element.parent();
          },
3a3ecabe   Imshann   init
41
42
      };
  });