Blame view

src/Slot/Slot.js 672 Bytes
3a3ecabe   Imshann   init
1
2
3
4
5
6
7
8
9
10
11
12
  class Slot {
      props = {
          content: String,
          context: Object,
      };
  
      useModules = ["$compile"];
  
      watch = {
          content: (newValue) => {
              if (newValue !== undefined) {
                  if (/<[^>]+>/.test(newValue)) {
a5fb53e0   Imshann   优化
13
                      this.parentElement.empty().append(
3a3ecabe   Imshann   init
14
15
16
17
18
19
20
21
22
23
24
25
                          $compile(newValue)(
                              $scope.context ? $scope.context : $scope
                          )
                      );
                  } else {
                      $element.text(newValue);
                  }
              }
          },
      };
      
      constructor() {
a5fb53e0   Imshann   优化
26
          this.parentElement = $element.parent();
3a3ecabe   Imshann   init
27
28
      }
  }